Bubble Sort

bubble_sort

#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");
}

Sumber:

4 thoughts on “Bubble Sort

    • tugas no 1 tidak saya temukan, hanya ada judulnya saja tapi content tidak saya temukan. coba kamu copy paste link nya di komentar ini ya

      terimakasih atas saran dan komennya.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s