Sunday 21 April 2024

Buble Sort

 #include<iostream>

using namespace std;

int main()

{

int temp;

//int x[]={10,5,2,7,8,3};

int x[]={17,23,12,00,49};

int j = sizeof(x)/sizeof(*x);

cout<<" X : ";

for(int i=0; i<j; i++)

{

cout<<x[i]<<" ";

}

cout<<endl;

for(int i=0;i<j;i++)

{

for(int h=0; h<j-1;h++)

{

if(x[h]>x[h+1])

{

temp=x[h];

x[h]=x[h+1];

x[h+1]=temp;

}

}

cout<<endl;

cout<<"Tahap : "<<i+1<<" : ";

for(int a=0;a<j;a++)

{

cout<<x[a]<<" ";


}

}

cout<<endl<<endl;

cout<<"Nilai yang Sudah terurut : ";

for(int d=0;d<j;d++)

{

cout<<x[d]<<" ";

}

}


No comments:

Post a Comment