-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_SELECTION_BUBBLE_SORT.cpp
131 lines (118 loc) · 2.13 KB
/
2_SELECTION_BUBBLE_SORT.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include<iostream>
#define N 8
using namespace std;
class sort
{
private:
float p[N];
public:
//------------------------------------------------------------
void enter_percentage()
{
float no;
for(int i=0;i<N;i++)
{
cout<<"Enter percentage : ";
cin>>no;
p[i]=no;
}
}
//------------------------------------------------------------
void display_percentage()
{
for(int i=0;i<N;i++)
{
cout<<"Percentage : "<<p[i]<<endl;
}
}
//------------------------------------------------------------
void selection_sort()
{
int i,j,k;
float temp;
for(i=0;i<N;i++)
{
k=i;
for(j=i+1;j<N;j++)
{
if(p[j]<p[k])
{
k=j;
}
}
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
cout<<"\n\n***SELECTION SORT***\n";
display_percentage();
}
//------------------------------------------------------------
void bubble_sort()//as bubble rises up smallest element up
{
int i,j;
float temp;
for(i=0;i<N-1;i++)
{
for(j=0;j<N-i-1;j++)
{
if(p[j]>p[j+1])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}
cout<<"\n\n***BUBBLE SORT***\n";
display_percentage();
}
//------------------------------------------------------------
void top_5()
{
int j=0;
for(int i=N-1;j<5;i--)
{
cout<<"Percentage : "<<p[i]<<endl;
j++;
}
}
//------------------------------------------------------------
};
main()
{
sort s1;
int op=-1;
while(op!=0)
{
cout<<"\n1.ENTER PERCENTAGE";
cout<<"\n2.DISPLAY";
cout<<"\n3.SELECTION SORT";
cout<<"\n4.BUBBLE SORT";
cout<<"\n5.TOP FIVE SCORES";
cout<<"\n6.EXIT";
cout<<"\n\nENTER CHOICE : ";
cin>>op;
switch(op)
{
case 1:
s1.enter_percentage();
break;
case 2:
s1.display_percentage();
break;
case 3:
s1.selection_sort();
break;
case 4:
s1.bubble_sort();
break;
case 5:
s1.top_5();
break;
case 6:
op=0;
break;
}
}
}