-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble-sort-on-array.cpp
More file actions
62 lines (48 loc) · 1.21 KB
/
Bubble-sort-on-array.cpp
File metadata and controls
62 lines (48 loc) · 1.21 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
//CSC 160 Final Exam 1
//Purpose:
//Author: Larsen J Close Most recent changes: 5/6/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
using namespace std; // using directive
void display(int x[], int y)
{
for(int d = 0; d < y; d++)
{
cout << setw(3) << x[d];
}
}
void sort(int p[], int q)
{
for(int i = 0; i < q; i++)
{
for (int j = 0; j < q-1; j++)
{
if (p[j] > p[j+1])
{
int temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}/*End inner for loop*/
}/*End outer for loop*/
}
int main ( void )
{
const int N = 10;
int P[N] = {17, 56, 39, 44, 72, 98, 66, 38, 83, 12};
cout << " P[] before being sorted:\n";
display(P, N);
sort(P, N);
cout << "\n\n P[] after being sorted:\n";
display(P, N);
cout << "\n\n";
system("pause");
return 0;
} //end main ( )
/* Display of above program
P[] before being sorted:
17 56 39 44 72 98 66 38 83 12
P[] after being sorted:
12 17 38 39 44 56 66 72 83 98
Press any key to continue . . .
*/