#include <conio.h>
#include <cstdlib>
using namespace std;
int total,data[10];
void input()
{
cout<<"buble sort\n\n";
cout<<"Masukkan berapa banyak arraynya = ";
cin>>total;
cout<<"\n";
for(int a=0;a<total;a++)
{
cout<<"\nMasukkan nilai pada INDEX ke ["<<a+1<<"] = ";
cin>>data[a];
}
}
void sort()
{
int temp;
for(int a=0;a<total-1;a++)
{
for(int b=0;b<total-1;b++)
{
if(data[b]>data[b+1])
{
temp=data[b+1];
data[b+1]=data[b];
data[b]=temp;
}
for(int a=0;a<total;a++)
{
cout<<data[a]<<" ";
}
cout<<"\n";
}
cout<<"\n";
}
}
void view()
{
for(int a=0;a<total;a++)
{
cout<<data[a]<<" ";
}
cout<<"\n";
getch();
}
int main()
{
input();
cout<<"\nsebelum di- sorting :";
view();
cout<<"\nProses pengurutan data : \n\n";
sort();
cout<<"\nHasil sorting :";
view();
}
0 Comments