File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Author: Shubhendra Singh
3+ Github: shubhendra-20
4+ */
5+
6+ #include <iostream>
7+ using namespace std;
8+
9+ void bubbleSort(int arr[], int n)
10+ {
11+ int i,j,t;
12+ bool swap;
13+ for (i = 0; i < n-1; i++)
14+ {
15+ swap = false;
16+ for (j = 0; j < n-i-1; j++)
17+ {
18+ if (arr[j] > arr[j+1])
19+ {
20+ t=arr[j];
21+ arr[j]=arr[j+1];
22+ arr[j+1]=t;
23+ swap=true;
24+ }
25+ }
26+ if (swap == false)
27+ break;
28+ }
29+ }
30+
31+ void printArray(int arr[], int n)
32+ {
33+ int i;
34+ for (i=0; i < n; i++)
35+ cout<<arr[i]<<" ";
36+
37+ }
38+
39+ int main()
40+ {
41+ int n,i;
42+ cin>>n;
43+ int arr[n];
44+ for(i=0;i<n;i++)
45+ {
46+ cin>>arr[i];
47+ }
48+ bubbleSort(arr, n);
49+ cout<<"Sorted array : ";
50+ printArray(arr, n);
51+ return 0;
52+ }
You can’t perform that action at this time.
0 commit comments