Minggu, 13 Oktober 2013

PROGRAM BUBLE SHORT ASCENDING C++

//---------------------------------------------------------------------------

#pragma hdrstop
#include <iostream.h>
//---------------------------------------------------------------------------

#pragma argsused
void main()
{
int A[100];
int c=1,i,j,k,p,x,data,idata;
cout << "Program Buble Short\n";
cout << "=====================\n\n";
cout << "masukan jumlah data(max. 100) : ";
cin >> data;
for (idata=0;idata<data;idata++)
{
cout << "Masukan data ke-" << idata+1 << " : ";
cin >> A[idata];
}

cout << "\nData sebelum di urutkan \n";
for (p=0;p<data;p++)
{
cout << A[p] << " ";
}

// Aval proses sorting
do{
x=0;
for (i=0;i<data-1;i++)
{
if (A[i] > A[i+1])
{
k=A[i];
A[i]=A[i+1];
A[i+1]=k;
x++;
}
}

cout << "\n\nLangkah-"<< c << "\n";
for (int p=0;p<data;p++)
{
cout << A[p] << " ";
}
c++;
}while (x>0);
// akhir proses ascending sorting

cout <<"\n\n";
system("pause");
}



Tidak ada komentar:

Posting Komentar