Created
September 14, 2021 06:21
-
-
Save tejus07/dfba59cf19875ff70d01aa169f93a020 to your computer and use it in GitHub Desktop.
the function named 'algorithm' takes an array and prints the sorted array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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