Wednesday, January 23, 2013
Contoh Listing Buble Sort Untuk C++
#
#
#
#
int data[10],data2[10];
int n;
void tukar(int a, int b)
{
int t;
t = data[b];
data[b] = data[a];
data[a] = t;
}
void bubble_sort()
{
for(int i=1;i<=n;i++)
{
for(int j=n; j>=i; j--)
{
if(data[j] < data[j-1]) tukar(j,j-1);
}
}
}
void main()
{
cout<<"===PROGRAM BUBBLE SORT==="<<endl;
cout<<"Nama : MATIUS ISAK "<<endl;
cout<<"NIM : 12119876 "<<endl;
cout<<"Kelas : 12.1G.12 "<<endl;
cout<<endl;
//Input Data
cout<<"Masukkan Jumlah Data : ";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"Masukkan data ke "<<i<<" : ";
cin>>data[i];
data2[i]=data[i];
}
bubble_sort();
cout<<"\n\n";
//tampilkan data
cout<<"Data Setelah di Sort : ";
for(int i=1; i<=n; i++)
{
cout<<" "<<data[i];
}
cout<<"\n\nSorting Selesai";
getch();
}
Silakan download Disini :
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment