-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathbubble_sort.cpp
More file actions
41 lines (35 loc) · 770 Bytes
/
Copy pathbubble_sort.cpp
File metadata and controls
41 lines (35 loc) · 770 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
#include<iostream>
#include<cmath>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int array_size;
cout<<"Enter the size of the array"<<endl;
cin>>array_size;
int array [array_size];
for (int i = 0; i < array_size; i++)
{
cin>>array[i];
}
int counter = 1;
while (counter<array_size)
{
for (int i = 0; i < array_size-counter; i++)
{
if (array[i]>array[i+1])
{
int temp = array[i];
array[i]= array[i+1];
array[i+1]= temp;
}
}
counter++;
}
for (int i = 0; i < array_size; i++)
{
cout<<array[i]<<endl;
}
return 0;
}