// ------------------------------- ------------------------------ --------------
#pragma hdrstop
#include <iostream.h>
// ------------------------------- ------------------------------ --------------
#pragma argsused
void main()
{
int A[100];
int c=1,i,j,k,p,x,data,idata;
cout<< "PRORAM BUBLE SHORT\n";
cout<< "======================\n\n";
cout << "Masukan Jumlah Data (max. 10) : ";
cin>> data;
for (idata=0;idata<data;idata++)
{
cout << "Masukan Data Ke- " << idata+1 << " : ";
cin >> A[idata];
}
cout << "\nData sebelum diurutkan\n";
for (p=0;p<data;p++)
{ cout << A[p] << " ";
}
// awal proses pengurutan
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 sorting descending
cout << "\n\n";
system ("pause");
}
// ------------------------------- ------------------------------ --------------
#pragma hdrstop
#include <iostream.h>
//
#pragma argsused
void main()
{
int A[100];
int c=1,i,j,k,p,x,data,idata;
cout<< "PRORAM BUBLE SHORT\n";
cout<< "======================\n\n";
cout << "Masukan Jumlah Data (max. 10) : ";
cin>> data;
for (idata=0;idata<data;idata++)
{
cout << "Masukan Data Ke- " << idata+1 << " : ";
cin >> A[idata];
}
cout << "\nData sebelum diurutkan\n";
for (p=0;p<data;p++)
{ cout << A[p] << " ";
}
// awal proses pengurutan
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 sorting descending
cout << "\n\n";
system ("pause");
}
//
Tidak ada komentar:
Posting Komentar