Program Buble shoort Dengan menggunakan C++

#include <iostream.h>
main()
{
int A[5]={3,4,1,2,8},i,j,tampung;
cout<<“sebelum sorting(Acak) : \n”;
for (i=0;i<5;i++)
{
cout<<A[i]<<“\t”;
}
for (i=0;i<5;i++)
{
for(j=5-1;j>=i;j–)
{
if (A[j]<A[j-1])
{
tampung=A[j];
A[j]=A[j-1];
A[j-1]=tampung;
}
}
}
cout <<“\n \n setelah sorting(Ascending) : \n”;
for (i=0;i<5;i++)
{
cout<<A[i]<<“\t”;
}
for (i=0;i<5;i++)
{
for(j=5-1;j>=i;j–)
{
if (A[j]>A[j-1])
{
tampung=A[j];
A[j]=A[j-1];
A[j-1]=tampung;
}
}
}
cout <<“\n \n setelah sorting (Descending): \n”;
for (i=0;i<5;i++)
{
cout<<A[i]<<“\t”;
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s