Nah ini contoh Program sorting , dengan Mengurutkan Bilangan ....
Listing Program
#include <iostream.h>
#include <conio.h>
main()
{
int JML,Z,data[100],A,B,P;
clrscr();
cout<<"Program Pengurut Bilangan\n";
cout<<"=========================\n";
cout<<"(1).Dari terkecil ke terbesar\n";
cout<<"(2).Dari terbesar ke terkecil\n";
cout<<"\n";
cout<<"PILIH MENU(1-2)....! =";cin>>P;
cout<<"\n";
switch(P)
{
case 1:
cout<<"Masukan jumlah data (maksimal 100)="; cin>>JML;
for(Z=1;Z<=JML;Z++)
{
cout<<"data ke"<<Z<<"=";cin>>data[Z];
}
for(Z=1;Z<JML;Z++)
{
for(A=Z+1;A<=JML;A++)
{
if(data[Z]>data[A])
{
B=data[Z];
data[Z]=data[A];
data[A]=B;
}
else
{
}
}
cout<<data[Z]<<endl;
}
cout<<data[Z]<<endl;
break;
case 2:
cout<<"Masukan jumlah data (maksimal 100)="; cin>>JML;
for(Z=1;Z<=JML;Z++)
{
cout<<"data ke"<<Z<<"=";cin>>data[Z];
}
for(Z=1;Z<JML;Z++)
{
for(A=Z+1;A<=JML;A++)
{
if(data[Z]<data[A])
{
B=data[Z];
data[Z]=data[A];
data[A]=B;
}
else
{
}
}
cout<<data[Z]<<endl;
}
cout<<data[Z]<<endl;
break;
}
getch();
}
Selamat Mencoba !!