Created
October 9, 2016 03:29
-
-
Save shaunlgs/455e2009c4cab3c7038b4ec3f1fe4338 to your computer and use it in GitHub Desktop.
This code is from Data Structure class UTM SPACE 2016
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
#include <stdio.h> | |
#include <conio.h> | |
void isihan_selitan(int, int []); | |
int main() | |
{ | |
int i, saiz=10, susun[10] = {24,64,10,5,6,31,15,20,56,34}; | |
printf("\n Data belum terisih :\n"); | |
for (i=0;i<10;i++) | |
printf("%3d",susun[i]); | |
isihan_selitan(saiz, susun); | |
printf("\n Data telah terisih mengikut turutan menaik :\n"); | |
for (i=0;i<10;i++) | |
printf("%3d",susun[i]); | |
getch(); | |
} | |
void isihan_selitan (int saiz_senarai,int tatasusunan[]) | |
{ | |
// Pembolehubah setempat | |
int item; | |
int laluan, titik_selitan; | |
//Badan fungsi | |
for (laluan = 1; laluan < saiz_senarai; laluan++) | |
{ | |
item = tatasusunan[laluan]; | |
titik_selitan = laluan; | |
while ( (titik_selitan > 0) && (tatasusunan[titik_selitan - 1] > item) ) | |
{ | |
tatasusunan[titik_selitan] = tatasusunan[titik_selitan - 1]; | |
titik_selitan--; | |
} | |
tatasusunan[titik_selitan] = item; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment