Created
September 27, 2017 02:11
-
-
Save RianWardana/b059492e4f62aae1f616c049e5bb8dcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nurian S Wardana | |
// Bubble sort array | |
#include <stdio.h> | |
void urutkanArray(int array[], int arrayLength) { | |
int lastIndex = arrayLength - 1; | |
int i, j, k, dummy; | |
for (i = 0; i < arrayLength; i++) { | |
for (j = lastIndex; j > i; j--) { | |
dummy = array[j]; | |
if (array[j] < array[j-1]) { | |
array[j] = array[j-1]; | |
array[j-1] = dummy; | |
} | |
} | |
printf("\n\nPutaran ke-%d\n", i + 1); | |
for (k = 0; k < arrayLength; k++) printf("%d ", array[k]); | |
} | |
} | |
int main() { | |
int array[] = {6,4,3,2,1}; | |
int arrayLength = sizeof(array) / sizeof(int); | |
int k; | |
printf("Sebelum sorting\n"); | |
for (k = 0; k < arrayLength; k++) printf("%d ", array[k]); | |
printf("\n"); | |
urutkanArray(array, arrayLength); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment