Skip to content

Instantly share code, notes, and snippets.

@kapilepatel
Created April 17, 2022 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kapilepatel/fa27e38cdbabf095143388dd22d42cef to your computer and use it in GitHub Desktop.
Save kapilepatel/fa27e38cdbabf095143388dd22d42cef to your computer and use it in GitHub Desktop.
Bubble sort CPP C++ C Plus Plus
#include <iostream>
using namespace std;
void printarr(int arr [], int n)
{
for(int i=0; i<n; i++)
{
cout <<arr[i] << " ";
}
cout << "\n";
}
void bubble_sort(int arr[], int n ){
int temp;
for(int i=0; i<n-1; i++)
{
for(int j=0; j<n-1-i; j++){
if(arr[j] > arr[j+1])
{
temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
printarr(arr, n);
}
}
int main(){
cout << "cpp in local pc";
int arr[] = {-2, 3, 4, -1, 5, -12, 6, 1, 3};
int n = sizeof(arr)/sizeof(int);
bubble_sort(arr, n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment