Created
August 29, 2015 04:07
-
-
Save anugrahbsoe/84eee0e97196d3fc5cce to your computer and use it in GitHub Desktop.
antrian
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> | |
#define n 10 | |
void awal(); | |
void masuk(); | |
void keluar(); | |
void tampil(); | |
int Q[n], counter, depan, belakang, bil; | |
void main() | |
{ | |
int kondisi = 1, pil; | |
awal(); | |
while (kondisi) { | |
printf("\nMENU CIRCULAR QUEUE"); | |
printf("\n1. Masuk Antrian"); | |
printf("\n2. Keluar Antrian"); | |
printf("\n3. Tampil Antrian"); | |
printf("\n4. Keluar Program"); | |
printf("\nPILIHAN : "); scanf("%i", &pil); | |
if (pil == 1) { | |
masuk(); | |
} else if (pil == 2) { | |
keluar(); | |
} else if (pil == 3) { | |
tampil(); | |
} else { | |
kondisi = 0; | |
} | |
} | |
printf("\nTERIMA KASIH..."); | |
} | |
void awal() { | |
depan = -1; | |
belakang = 0; | |
counter = 0; | |
} | |
void masuk() { | |
if (counter < n) { | |
printf("\nMasukkan bilangan: "); | |
scanf("%i", &bil); | |
depan = (depan+1) % n; | |
counter ++; | |
Q[depan] = bil; | |
} else { | |
printf("\nANTRIAN PENUH"); | |
} | |
} | |
void keluar() { | |
if (counter > 0) { | |
bil = Q[belakang]; | |
Q[belakang] = 0; | |
belakang = (belakang+1) % n; | |
printf("\nBilangan %i sudah dihapus", bil); | |
counter --; | |
} else { | |
printf("\nANTRIAN KOSONG"); | |
} | |
} | |
void tampil() { | |
int i; | |
printf("\nISI ANTRIAN"); | |
for (i=0; i<n; i++) { | |
printf("%4i", Q[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment