Skip to content

Instantly share code, notes, and snippets.

@m-ahmedy
Last active May 22, 2017 16:39
Show Gist options
  • Save m-ahmedy/c4f17600b598d06a0bfcfd4ee3c87d74 to your computer and use it in GitHub Desktop.
Save m-ahmedy/c4f17600b598d06a0bfcfd4ee3c87d74 to your computer and use it in GitHub Desktop.
arrSort
#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;
}
#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;
}
@TarekkMA
Copy link

Why are you using continue; after swapper function ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment