Skip to content

Instantly share code, notes, and snippets.

@tejus07
Created September 14, 2021 06:21
Show Gist options
  • Select an option

  • Save tejus07/dfba59cf19875ff70d01aa169f93a020 to your computer and use it in GitHub Desktop.

Select an option

Save tejus07/dfba59cf19875ff70d01aa169f93a020 to your computer and use it in GitHub Desktop.
the function named 'algorithm' takes an array and prints the sorted array.
/*
* Pesudo Code
for(int times=1; times<n-1; times++){
//repeated swapping
for(int j=0; j<=n - times -1; j++){
if(arr[j]>arr[j+1]){
swap(arr[j],arr[j+1]);
}
}
}
*/
#include <iostream>
using namespace std;
//Sort the elements in increasing order
void algorithm(int arr[],int n){
for(int times=1; times<n-1; times++){
//repeated swapping
for(int j=0; j<=n - times -1; j++){
if(arr[j]>arr[j+1]){
swap(arr[j],arr[j+1]);
}
}
}
}
int main() {
int arr[] = {83,1,45,95,45,52,11,47,0,45,67,82};
int n = sizeof(arr)/sizeof(int);
algorithm(arr,n);
for(auto x : arr){
cout << x <<",";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment