#include<iostream.h>
#include<conio.h>
int data[10];
int n;
//Creted by Krisna Anggara
void tukar(int a, int b)
{
int t;
t=data[b];
data[b]=data[a];
data[a]=t;
}
void asc()
{
int temp,i,j;
for(i=1;i<n;i++)
{
temp=data[i];
j=i-1;
while(data[j]>temp && j>=0)
{
data[j+1]=data[j];
j--;
}
data[j+1]=temp;
}
cout<<"Ascending sort selesai ! "<<endl;
cout<<"Data : "<<endl;
for(int i=0;i<n;i++)
{
cout<<data[i]<<" ";
}
cout<<endl;
}
void desc()
{
int temp,i,j;
for(i=1;i<n;i++)
{
temp=data[i];
j=i-1;
while(data[j]<temp && j>=0)
{
data[j+1]=data[j];
j--;
}
data[j+1]=temp;
}
cout<<"Descending sort selesai ! "<<endl;
cout<<"Data : "<<endl;
for(int i=0;i<n;i++)
{
cout<<data[i]<<" ";
}
cout<<endl;
}
void input()
{
cout<<"Masukkan jumlah data = ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Masukkan data ke - "<<(i+1)<<" = " ;
cin>>data[i];
}
}
void main()
{
int pil;
clrscr();
do
{
clrscr();
cout<<"1. Input Data"<<endl;
cout<<"2. Urutkan"<<endl;
cout<<"3. Exit"<<endl;
cout<<"Masukkan Pilihan anda = ";
cin>>pil;
switch(pil)
{
case 1: input();break;
case 2:
asc();
desc();
break;
}
getch();
}
while(pil!=4);
}