# include iostream.h>
# include conio.h>
void main()
{
float L[50];
int n,i,j;
float temp;
//Input data
cout<<"Masukkan banyak data : ";
cin>>n;
cout<<"\nMasukkan Nilai";
//Membuat tabel
cout<<"\n=============";
cout<<"\n| i | Nilai |";
cout<<"\n|-----------|";
int y = 7;
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++;
}
y=7;
//Input nilai data
for (i=1;i<=n;i++)
{
gotoxy(9,y);
cin>>L[i];
y++;
}
cout<<"\nUrutkan secara : ";
cout<<"\n1. Ascending";
cout<<"\n2. Descending";
int pilih;
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 kondisi
if (pilih==1)
{
//Mengurutkan ascending
for (i=1;i<=n;i++)
{
for (j=n;j>=2;j--)
{
if (L[j] < L[j-1])
{
//Menukar nilai
temp=L[j];
L[j]=L[j-1];
L[j-1]=temp;
}
}
}
}
else
{
//Mengurutkan descending
for (i=1;i<=n;i++)
{
for (j=n;j>=2;j--)
{
if (L[j] > L[j-1])
{
//Menukar nilai
temp=L[j];
L[j]=L[j-1];
L[j-1]=temp;
}
}
}
}
//Membuat tabel data yang terurut
y=7;
gotoxy(17,3);
cout<<"Data Setelah di Urut";
gotoxy(20,4);
cout<<"=============";
gotoxy(20,5);
cout<<"| i | Nilai |";
gotoxy(20,6);
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,(7+n));
cout<<"=============";
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
Bubble Sort
Label: C++
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar