# include iostream.h>
# include conio.h>
void main()
{
float L[50];
int n,i,j;
float p;
int pilih;
do
{
clrscr();
cout<<"==================";
cout<<"\n| Insertion Sort |";
cout<<"\n==================";
cout<<"\n";
//Input Data
cout<<"\nMasukkan banyak data : ";
cin>>n;
//Tampilan berupa tabel
cout<<"\nMasukkan Nilai";
cout<<"\n=============";
cout<<"\n| i | Nilai |";
cout<<"\n|-----------|";
int y = 11;
gotoxy(1,(y+n));
cout<<"=============";
for (i=1;i<=n;i++)
{
gotoxy(3,y);
cout< gotoxy(1,y);
cout<<("|");
gotoxy(5,y);
cout<<"|";
gotoxy(13,y);
cout<<"|";
y++;
}
//Input nilai data
y=11;
for (i=1;i<=n;i++)
{
gotoxy(9,y);
cin>>L[i];
y++;
}
cout<<"\nUrutkan secara : ";
cout<<"\n1. Ascending";
cout<<"\n2. Descending";
do //validasi pilihan
{
cout<<"\nMasukkan nomor nya saja : ";
cin>>pilih;
if ((pilih!=1)&&(pilih!=2))
cout<<"\nPilihan tidak valid, ulangi!";}
while((pilih != 1) && (pilih!= 2));
//cek pilihan
if (pilih==1)
{
for (i=2;i<=(n);i++)
{
p = L[i];
j = i-1;
while ((j>0)&&(L[j] > p))
{
L[j + 1] = L[j];
j = j-1;
}
L[j+1] = p;
}
}
else
{
for (i=2;i<=(n);i++)
{
p = L[i];
j = i-1;
while ((j>0)&&(L[j] < p))
{
L[j + 1] = L[j];
j = j-1;
}
L[j+1] = p;
}
}
//Tampilan data terurut dalam tabel
y=11;
gotoxy(17,7);
cout<<"Data Setelah di Urut";
gotoxy(20,8);
cout<<"=============";
gotoxy(20,9);
cout<<"| i | Nilai |";
gotoxy(20,10);
cout<<"-------------";
for (i=1;i<=n;i++)
{
gotoxy(20,y);
cout<<"|";
gotoxy(22,y);
cout< gotoxy(24,y);
cout<<"|";
gotoxy(28,y);
cout<
cout<<"|";
y++;
}
gotoxy(20,(11+n));
cout<<"=============";
gotoxy(1,n+16);
do
{
cout<<"\n1. Ulang Program";
cout<<"\n2. Keluar";
cout<<"\nMasukkan pilihan : ";
cin>>pilih;
if (pilih!=1 && pilih!=2)
{
cout<<"Pilihan tidak valid! Ulangi!";
}
}
while(pilih!=1 && pilih!=2);
}
while(pilih!=2);
getch();
}
Label
- Adekdik Software (1)
- Aplikasi Iseng (16)
- C++ (7)
- Download (2)
- Excel (1)
- Google Map (1)
- Iseng (1)
- Nambah ilmu (32)
- Pascal (20)
- Super Iseng (2)
- VB .Net (21)
- VB 6 (1)
Selasa, 25 November 2008
Insertion Sort
Label: C++
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar