#include "stdio.h"
#include "conio.h"
#define n 7
void Tukar(int &a, int &b); //header function pass by refrence
void View(int arr[]); //header function pass by value
void main()
{
int A[n] = {15,10,7,22,17,5,12};
int X, I, K;
printf("Sebelum di-sort\n");
View(A);
for (I=0;I<=n-1;I++) { for (int K=n-1;K>=I;K--)
if (A[K-1]> A[K])
Tukar(A[K],A[K-1]); //fungsi tukar
View(A);
}
printf("Sesudah di-sort\n");
View(A);
getch();
}
void Tukar(int &a, int &b)
{
int X;
X = a;
a = b;
b = X;
}
void View(int arr[])
{
for (int I=0; I <= n-1; I++)
printf("%3i", arr[I]);
printf("\n");
}
Jumat, 21 Desember 2012
Bubble Sort
Langganan:
Posting Komentar (Atom)













0 komentar:
Posting Komentar