Last active
May 22, 2017 16:39
-
-
Save m-ahmedy/c4f17600b598d06a0bfcfd4ee3c87d74 to your computer and use it in GitHub Desktop.
arrSort
This file contains 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
#include <iostream> | |
using namespace std; | |
void swapper(int& x,int& y) | |
{ | |
int temp=x; | |
x=y; | |
y=temp; | |
} | |
int main() | |
{ | |
int length; | |
cout<<"Enter array length: "; | |
cin>>length; | |
int arr[length]= {0}; | |
for(int i=0 ; i<length ; i++) | |
{ | |
cout<<"Enter data #"<<i+1<<" : "; | |
cin>>arr[i]; | |
} | |
for(int i=0 ; i<length ; i++) | |
for(int j=i+1 ; j<length ; j++) | |
if(arr[j]>arr[i]) // > for Decending , < for Ascending | |
{ | |
swapper(arr[i],arr[j]); | |
continue; | |
} | |
for(int i=0 ; i<length ; i++)cout<<"Data #"<<i+1<<" : "<<arr[i]<<endl; | |
} |
This file contains 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
#include <iostream> | |
using namespace std; | |
void swapper(int& x,int& y) | |
{ | |
int temp=x; | |
x=y; | |
y=temp; | |
} | |
void arrSort(int arr[],int length){ | |
for(int i=0 ; i<length ; i++) | |
for(int j=i+1 ; j<length ; j++) | |
if(arr[j]>arr[i]) // > for Decending , < for Ascending | |
{ | |
swapper(arr[i],arr[j]); | |
continue; | |
} | |
} | |
int main() | |
{ | |
int length; | |
cout<<"Enter array length: "; | |
cin>>length; | |
int arr[length]= {0}; | |
for(int i=0 ; i<length ; i++) | |
{ | |
cout<<"Enter data #"<<i+1<<" : "; | |
cin>>arr[i]; | |
} | |
arrSort(arr,length); | |
for(int i=0 ; i<length ; i++)cout<<"Data #"<<i+1<<" : "<<arr[i]<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why are you using
continue;
afterswapper
function ?