Anak Indonesia Asli

Home » Tutorial » Contoh source code forklift.c

Contoh source code forklift.c

Berikut ini adalah contoh source code untuk penyelesain algoritma forklift menggunakan C.

#include <stdio.h>
#include <conio.h>

void cariterbesar(int input[], int, int, int kanan[]);
void pindahkan(int input[], int, int, int, int kanan[]);

int main(){
int indeks=0, a, i, j, k, banyak, input[20], terbesar, ke, kanan[20];

printf(“Berapa Inputan : “);
scanf(“%d”, &banyak);
printf(“Masukkan inputan satu persatu : \n”);
for(i=0; i<banyak; i++){
printf(“Input ke %d : “, i+1);
scanf(“%d”, &input[i]);
}

printf(“\nInput :”);
for(i=0; i<banyak; i++){
printf(“%d “, input[i]);
}

cariterbesar(input, banyak, indeks, kanan);

getch();
return 0;
}

void cariterbesar(int input[], int banyak, int indeks, int kanan[]){
int j, terbesar, ke;
terbesar = input[0];
for(j=0; j<banyak; j++)
if(input[j]>=terbesar){
terbesar=input[j];
ke = j;
}

//printf(“\nTerbesar input ke %d : %d\n”, ke+1, terbesar);
pindahkan(input, ke, banyak, indeks, kanan);
}

void pindahkan(int input[], int ke, int banyak, int indeks, int kanan[]){
int y=0, l=0, w=0;

int baru = banyak;
int bykkn = banyak-ke;

printf(“\n\t\t==> “);
while(w<bykkn){
kanan[indeks+w]=input[ke+w];
printf(“%d “, kanan[indeks+w]);
w++;
}
printf(“==>”);

printf(“\n\t\t\t\thasil pindahan :”);
for(int x=0; x<indeks; x++)
printf(“%d “, kanan[x]);

while(y<bykkn){
kanan[indeks+y]=input[ke+y];
printf(“%d “, kanan[indeks+y]);
y++;
}

baru = baru-1;

while(l<baru){
input[l+ke]=input[l+ke+1];
l++;
}

printf(“\n\t\t<== “);
for(int t=ke; t<baru; t++){
printf(“%d “, input[t]);
}
printf(“<==”);

if(baru>0){
printf(“\nInput :”);
}

for(int i=0; i<baru; i++){
printf(“%d “, input[i]);
}

if(baru!=0){
indeks++;
cariterbesar(input, baru, indeks, kanan);
}
}

Berikut ini adalah hasil compile-annya

compile1.jpg


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

%d bloggers like this: