#include "stdio.h"
void main()
{ int queue[5];
int depan = -1;
int belakang = -1;
int pilihan, data, i;
do{
printf("MENU\n");
printf("1. ENQUEUE\n2. DEQUEUE\n3. VIEW\n4. EXIT\n");
printf("Pilihan = "); scanf("%d", &pilihan);
switch (pilihan)
{
case 1: //enqueue
//apakah queue belum penuh?
if (belakang < 4 )
{ printf("Data Masuk = "); scanf("%d", &data);
queue[belakang+1] = data;
belakang++;
if (belakang == 0)
depan = 0;
}
else
printf("Queue penuh!\n");
break;
case 2: //dequeue
//apakah queue belum kosong?
if (depan <= belakang)
{ printf("Data keluar = %d\n", queue[depan]);
depan++;
}
else
printf("Queue kosong!\n");
break;
case 3:
for(i=depan; i<=belakang; i++)
printf("%d ", queue[i]);
printf("\n");
break;
}
}while (pilihan != 4);
}
Artikel terkait:
Queue dengan Liked List
Queue Array Java
Queue Linked List Java
Queue Library Java
No comments:
Post a Comment