Pengurutan data dengan Bubble sort melalui input

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

#define MAX 100

void InputArray(int input[], int N)
{
cout<<"# Masukkan nilai : "<<endl;
for(int i=0; i<N; i++)
      {cout<<"Nilai "<<i+1<< " = ";
      cin>>input[i];}
cout<<""<<endl;
}


void TampilkanArray(int input[], int n)
{
for (int i=0; i<n; i++)
{cout<<"Nilai "<<i+1<< " = "<<input[i]<<endl;}
cout<<""<<endl;
}

//utama
int main()
{
int input[MAX];
int n;
int temp;
int j,k;

cout<<""<<endl;
cout<<"Mengurutkan Data dengan Bubble Sort"<<endl;
cout<<"==================================="<<endl;
cout<<""<<endl;
cout<<"Masukkan jumlah data (maks 100): ";cin>>n;
cout<<""<<endl;
InputArray(input, n);


for (j=0; j<n-1; j++) {
for (k=n-1; k>=(j+1); k--)
{
if (input[k] < input[k-1])
{temp = input[k];input[k] = input[k-1];input[k-1] = temp}
}
}
cout<<""<<endl;
cout<<"# Setelah pengurutan : "<<endl;
TampilkanArray(input, n);
return 0;
}

No comments on "Pengurutan data dengan Bubble sort melalui input

Leave a Reply