- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBu_Sort.cpp
More file actions
Latest commit
37 lines (30 loc) · 601 Bytes
/
Copy pathBu_Sort.cpp
File metadata and controls
37 lines (30 loc) · 601 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
#include<iostream>
usingnamespacestd;
//Time Complexity: 0(n^2)
//Space Complexity: 0(1)
voidBubble_sort (int A[], int n)
{
int i, j, temp;
for (i = 0; i < n; i++)
{
for (j = 0; j < n - 1; j++)
{
if (A[j] > A[j + 1])
{
temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;
}
}
}
}
intmain()
{
int B[5];
cout << "Enter the 5 Array input: ";
for (int i = 0; i < 5; i++)
{
cin >> B[i];
}
Bubble_sort (B, 5);
}