ALGORITMANYA:
Deklarasi:
larik= Array[1..100] of int
i,a : byte
k : larik
j.bantu : int
Deskripsi:
for i <- 1 to n do
for j <- i+1 to n do
if x[i]>x[j] then
tukar (x[i], x[j])
end if
end for
end for
SOURCE CODEnya:
#include <iostream.h>
#include <conio.h>
void baca(int A[],int n){
int i;
for (i=0; i<n; i++)
{cout<<"Data Ke- " <<i+1<< " : ";
cin>>A[i];
}
}
void cetak(const int A[], int n){
int i;
for (i=0; i<n; i++)
cout<<A[i]<<"";
cout<<endl;
}
void tukar(int *a, int *b){
int temp;
temp = *a;
*a=*b;
*b=temp;
}
void buble_sort(int x[],int n){
int i,j;
for (i=0; i<n-1; i++)
for (j=1; j<n; j++)
if (x[i] >x[j]) tukar(&x[i], &x[j]);
}
int main(){
int data[8], n;
cout<<"Banyak Data: ";
cin>>n;
baca(data,n);
cetak(data,n);
buble_sort(data,n);
cetak(data,n);
getch();
return 0;
}
0 Komentar