forked from ArunHarish/Sorting-Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·40 lines (32 loc) · 1002 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var QuickSort = require("./QuickSort/QuickSort.js");
var MergeSort = require("./MergeSort/MergeSort.js");
var HeapSort = require("./HeapSort/HeapSort.js");
var BubbleSort = require("./BubbleSort/BubbleSort.js");
function generateRandom() {
var random = new Array(1000000);
for(var x = 0; x < random.length; x++) {
random[x] = Math.floor(1 + Math.random() * 99);
}
return random;
}
function check(a, sortType) {
for(var x = 1; x < a.length; x++) {
if(!sortType && a[x] > a[x-1] || sortType && a[x] < a[x - 1])
return false;
}
return true;
}
function test() {
var t1 = (new Date()).getTime();
var t2;
var quickSample = generateRandom();
//Function goes here
t1 = (new Date().getTime());
var qs = new QuickSort(quickSample);
console.log("Started Quick sort...");
qs.sort(1);
t2 = (new Date()).getTime();
console.log("Quick Sort Time: "+ (t2 - t1));
console.log(check(quickSample, 1))
}
test();