-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMyArray.h
95 lines (86 loc) · 2.31 KB
/
MyArray.h
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
89
90
91
92
93
94
95
#ifndef MYARRAY_H_INCLUDED
#define MYARRAY_H_INCLUDED
#include <iostream>
#include <stdlib.h> //Random
#include <time.h> //Use as a random seed
#include "Algorithms.h"
class MyArray
{
private:
int arr_size = 0;
int *arr;
char order;
char algorithm;
void generate_array()
{
/*
1. Crescent
2. Decrescent
3. Random
*/
arr = new int[arr_size];
switch (order)
{
case '1':
for (int i = 0; i < arr_size; i++)
arr[i] = i;
break;
case '2':
for (int i = arr_size - 1; i >= 0; i--)
arr[i] = arr_size - 1 - i;
break;
case '3':
srand (time(NULL));
for (int i = 0; i < arr_size; i++)
arr[i] = rand() % arr_size;
break;
}
}
public:
MyArray(int a_size, char ord, char alg)
{
arr_size = a_size;
order = ord;
algorithm = alg;
generate_array();
}
~MyArray()
{
delete arr;
}
void sort_array()
{
/*
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
*/
switch(algorithm)
{
case '1':
bubble_sort(arr,arr_size);
break;
case '2':
insertion_sort(arr,arr_size);
break;
case '3':
selection_sort(arr,arr_size);
break;
case '4':
quick_sort(arr,0,arr_size-1);
break;
case '5':
merge_sort(arr,0,arr_size-1);
break;
case '6':
heap_sort(arr,arr_size);
break;
case '7' :
radixsort(arr , arr_size);
break;
case '8':
pigeonholeSort(arr, arr_size);
}
}
};
#endif // MYARRAY_H_INCLUDED