Mengurutkan Angka menggunakan Metode Bubble Sort C++ (Statis)
Program C++ Mengurutkan angka menggunakan metode bubble sort sederhana. :
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
main (){
int k, i, temp;
int L[9];
L[0] = 1;
L[1] = 8;
L[2] = 3;
L[3] = 6;
L[4] = 2;
L[5] = 7;
L[6] = 5;
L[7] = 4;
L[8] = 9;
cout<<"Data Sebelum diurutkan : \n"<<endl;
for (i=0;i<=8;i++){
cout<<L[i]<<" , ";
}
for (i=0;i<=8;i++)
for (k=0;k<=8;k++)
if(L[k]>L[k+1])
{
temp = L[k];
L[k]=L[k+1];
L[k+1]=temp;
}
cout<< "\n\nData Setelah Diurutkan :\n " <<endl;
for(i=0; i<=8;i++)
cout<<L[i]<<" , ";
getch();
}
Tampilan :
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
main (){
int k, i, temp;
int L[9];
L[0] = 1;
L[1] = 8;
L[2] = 3;
L[3] = 6;
L[4] = 2;
L[5] = 7;
L[6] = 5;
L[7] = 4;
L[8] = 9;
cout<<"Data Sebelum diurutkan : \n"<<endl;
for (i=0;i<=8;i++){
cout<<L[i]<<" , ";
}
for (i=0;i<=8;i++)
for (k=0;k<=8;k++)
if(L[k]>L[k+1])
{
temp = L[k];
L[k]=L[k+1];
L[k+1]=temp;
}
cout<< "\n\nData Setelah Diurutkan :\n " <<endl;
for(i=0; i<=8;i++)
cout<<L[i]<<" , ";
getch();
}
Tampilan :
Comments
Post a Comment