forked from piyush-kash/Hacktober2021-cpp-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble sort.cpp
More file actions
41 lines (40 loc) · 741 Bytes
/
bubble sort.cpp
File metadata and controls
41 lines (40 loc) · 741 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 <algorithm>
using namespace std;
void bubbleSort(int arr[], int n)
{
int i, j;
bool swapp;
for (i = 0; i < n-1; i++)
{
swapp = false;
for (j = 0; j < n-i-1; j++)
{
if (arr[j] > arr[j+1])
{
swap(arr[j], arr[j+1]);
swapp = true;
}
}
if (swapp == false)
break;
}
}
void printArray(int arr[], int n)
{
int i;
for (i=0; i < n; i++)
cout<<arr[i]<<" ";
}
int main()
{ int n;
cin>>n;
int arr[1000000];
for(int i=0;i<n;i++)
{cin>>arr[i];
}
bubbleSort(arr, n);
printArray(arr, n);
return 0;
}
© 2020 GitHub, Inc.