What sorting algorithm is this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
int main()
{
int num[100],ans,x,y,decoy;
cout<< "Enter how many numbers to include: ";
cin>> ans;
cout<< "Enter "<<ans << " numbers: \n";
for (x=0;x<ans;x++)
{
cin>> num[x];
}
for (x=0;x<ans;x++)
{
for (y=0;y<ans;y++)
{
if (num[y]>num[x])
{
decoy=num[y];
num[y]=num[x];
num[x]=decoy;
}
}
}
cout<< "Ascending order: "<<endl;
for (x=0;x<ans;x++)
{
cout<< num[x] << endl;
}
return 0;
}
| |
Last edited on
I believe that is a bubble sort you are doing
Topic archived. No new replies allowed.