#include <iostream.h>
#include <conio.h>
void tambahData(int nilai [], int ukuranArray)
{
int i;
for(i=0;i<ukuranArray;i++)
{
cout<<"Data ke-"<<(i+1)<<" :";
cin>>nilai[i];
}
}
void insertingSort(int nilai[],int ukuranArray)
{
int j, i, index;
for(i=0;i<ukuranArray;i++)
{
index=nilai[i];
j=i;
while((j>0)&&(nilai[j-1]>index))
{
nilai[j]=nilai[j-1];
j--;
}
nilai[j]=index;
}
}
void lihatData(int nilai[], int ukuranArray)
{
int i;
for(i=0;i<ukuranArray;i++)
{
cout<<"Data ke-"<<(i+1)<<" :"<<nilai[i];
cout<<endl;
}
}
main()
{
int n,cari;
int data[100];
cout<<"Inserting Sort";
cout<<endl<<endl;
cout<<"Banyak Data :";
cin>>n;
tambahData(data,n);
insertingSort(data,n);
cout<<endl;
lihatData(data,n);
getch();
}
Categories: Pemrograman
0 komentar:
Posting Komentar