forked from loiane/javascript-datastructures-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-UsingSortingAlgorithms.js
executable file
·90 lines (53 loc) · 1.49 KB
/
02-UsingSortingAlgorithms.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function createNonSortedArray(size){
var array = new ArrayList();
for (var i = size; i> 0; i--){
array.insert(i);
}
return array;
}
function createRandomNonSortedArray(){
var array = new ArrayList();
array.insert(3);
array.insert(5);
array.insert(1);
array.insert(4);
array.insert(2);
return array;
}
console.log('********** Bubble Sort **********');
var array = createNonSortedArray(5);
console.log(array.toString());
array.bubbleSort();
console.log(array.toString());
console.log('********** Modified Bubble Sort **********');
array = createNonSortedArray(5);
console.log(array.toString());
array.modifiedBubbleSort();
console.log(array.toString());
console.log('********** Selection Sort **********');
array = createNonSortedArray(5);
console.log(array.toString());
array.selectionSort();
console.log(array.toString());
console.log('********** Insertion Sort **********');
array = createRandomNonSortedArray();
console.log(array.toString());
array.insertionSort();
console.log(array.toString());
console.log('********** Merge Sort **********');
array = createNonSortedArray(8);
console.log(array.toString());
array.mergeSort();
console.log(array.toString());
console.log('********** Quick Sort **********');
array = new ArrayList();
array.insert(3);
array.insert(5);
array.insert(1);
array.insert(6);
array.insert(4);
array.insert(7);
array.insert(2);
console.log(array.toString());
array.quickSort();
console.log(array.toString());