-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathBubble Sort.cpp
More file actions
66 lines (34 loc) · 942 Bytes
/
Bubble Sort.cpp
File metadata and controls
66 lines (34 loc) · 942 Bytes
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
#include <iostream>
#include <climits>
using namespace std;
void bubble_sort (int arr[], int n)
{
for (int itr = 1; itr <= n-1; itr++)
{
// Pairwise Swapping in the unsorted array elements
for (int j = 0; j<= (n-itr-1) ; j++)
{
if (arr[j] > arr[j+1])
{
swap (arr[j], arr[j+1]);
}
}
}
}
int main()
{
int num, key;
cout << "Enter the number of elements in array: ";
cin >> num; // taking the no of elements in array
int a[1000]; // max constraint size
for (int i = 0; i < num; i++)
{
cin >> a[i];
}
bubble_sort(a,num);
for (int i =0; i<num; i++)
{
cout << a[i] << " , ";
}
return 0;
}