#include <conio.h>
#include <cstdlib>
using namespace std;
int total,data[10];
void input()
{
cout<<"Exchange sort\n\n";
cout<<"Masukkan berapa banyak arraynya = ";
cin>>total;
cout<<"\n";
for(int a=0;a<total;a++)
{
cout<<"\nMasukkan nilai pada INDEX ke ["<<a+1<<"] = ";
cin>>data[a];
}
}
void sort()
{
int temp, b=0;
for(int a=0;a<total-1;a++)
{
for(int b=a+1;b<total;b++)
{
if(data[a]>data[b])
{
temp=data[a];
data[a]=data[b];
data[b]=temp;
}
for(int a=0;a<total;a++)
{
cout<<data[a]<<" ";
}
cout<<"\n";
}
cout<<"\n";
}
}
void view()
{
for(int a=0;a<total;a++)
{
cout<<data[a]<<" ";
}
cout<<"\n";
getch();
}
int main()
{
input();
cout<<"\nsebelum di- sorting :";
view();
cout<<"\nProses pengurutan data : \n\n";
sort();
cout<<"\nHasil sorting :";
view();
}
0 Comments