Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions C++/bubble_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<iostream>
using namespace std;
void bubble_sort(int arr[],int n)
{
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(arr[j]>arr[j+1])
swap(arr[j],arr[j+1]);
}
}
}
void print(int arr[],int size)
{
int i;
for(i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
cout<<"\n";
}
int main()
{
int arr[]={2,20,10,8,3,6,9};
int n=sizeof(arr)/sizeof(arr[0]);
cout<<"Array before Sorting"<<endl;
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
cout<<"Array after Sorting"<<endl;
bubble_sort(arr,n);
print(arr,n);
return 0;


}
Binary file added C++/bubble_sort.exe
Binary file not shown.