Program C++ Pengurutan Data (Sorting) dengan Metode Bubble Sort


Script

/*program sorting data dengan metode buble short*/

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
int main ()
{
 int NumList [8]={5,34,32,25,75,42,22,2};
 int temp;
 cout<<"Data Sebelum Diurutkan : \n";
 for(int d=0;d<8;d++)
 {
 cout<<setw(3)<<NumList[d];
 }
 
 cout<<"\n\n";for (int i =0; i<8;i++)
 for(int i=0; i<7;i++)
 if (NumList[i]>=NumList[i+1])
 {
 temp = NumList[i];
 NumList[i]=NumList[i+1];
 NumList[i+1]=temp;
 }
 cout<<"Data setelah diurutkan :\n";
 for (int i=0;i<7;i++)
 cout<<setw(3)<<NumList[i]<<endl<<endl;


getche ();
}

Hasil

ScreenHunter_198 Feb. 22 16.12

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