-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.cpp
More file actions
36 lines (34 loc) · 782 Bytes
/
Copy pathBubbleSort.cpp
File metadata and controls
36 lines (34 loc) · 782 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
#include <iostream>
using namespace std;
void BubbleSort(int* arr,int size){
int temp;
int count;
for (size_t i = 0; i < size-1; i++)
{
for (size_t j = 0; j < size-1; j++)
{
if (arr[j] > arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
count--;
}
else{
count++;
}
if (count == size-1)
{
return;
}
}
}
}
int main(){
int arr[10] = {78,92,55,62,77,97,11,52,88,29};
BubbleSort(arr, sizeof(arr)/sizeof(int));
for (size_t i = 0; i < sizeof(arr)/sizeof(int); i++){
cout<<arr[i]<<" ";
}
return 0;
}