forked from donghunryou/LAB2_04
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (57 loc) · 1.56 KB
/
main.cpp
File metadata and controls
80 lines (57 loc) · 1.56 KB
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
#include<iostream>
#include<ctime>
using namespace std;
void swap(int& a, int& b);
void bubble_sort(int* array, unsigned int size);
void insertion_sort(int* array, unsigned int size);
void selection_sort(int* array, unsigned int size);
void max_heapify(int*array, int index, int heap_size);
void heap_sort(int*array, unsigned int size);
int main()
{
srand(time(0));
int size;
int type;
int array[100];
cout <<"Give me the size (max=100) : ";
cin >> size ;
for (int i=0; i<size; i++)
array[i] = rand() % size ;
for (int i=0; i<size; i++)
cout << array[i] << ' ';
cout << endl;
cout <<"Give me the type of algorithm (0:Bubble, 1:Insertion, 2:Selection) : ";
cin >> type;
if (type == 0)
bubble_sort(array, size);
else if (type == 1)
insertion_sort(array, size);
else if (type == 2)
selection_sort(array, size);
for (int i=0; i<size; i++)
cout << array[i] << ' ';
}
void swap(int& a, int& b){
int temp;
temp = a;
a = b;
b = temp;
}
void bubble_sort(int* array, unsigned int size){
}
void insertion_sort(int* array, unsigned int size){
}
void selection_sort(int* array, unsigned int size){
}
void max_heapify(int*array, int index, int heap_size){
}
void heap_sort(int*array, unsigned int size){
int heap_size = size;
for (int i = size/2-1; i>=0; i--)
max_heapify(array,i,heap_size);
for (int i = size - 1; i>0; i--)
{
swap(array[0], array[i]);
max_heapify(array, 0, --heap_size);
}
}