Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<conio.h>
- #include<stdio.h>
- #define max 5
- int queue[max], front=0, rear=0;
- int menu();
- void queue();
- void dequeue();
- void display();
- void main();
- {
- int ch;
- clrscr();
- printf("\nQueue menggunakan Array\n");
- do
- {
- ch=menu();
- switch(ch)
- {
- case 1: enqueue();
- break;
- case 2: dequeue();
- break;
- case 3: display();
- break;
- case 4: exit();
- break;
- default:printf("\n Masukan Pilihan yang Tersedia!!!");
- }
- }while(1);
- }
- int menu()
- {
- int ch;
- printf("\n1. ENQUEUE \n2. DEQUEUE \n3. TAMPILKAN \n4. EXIT");
- printf("\nMasukkan Pilihan : ");
- scanf("%d", &ch);
- return ch;
- }
- void enqueue()
- {
- int element;
- if(rear==max)
- {
- printf("\nOverflow");
- }
- else
- {
- printf("\nMasukkan Elemen : ");
- scanf("%d", &element);
- queue[rear++]=element;
- printf("\n Enqueue Elemen %d, Rear %d", element,rear);
- }
- }
- void dequeue()
- {
- if(rear==front)
- {
- printf("\nUnderflow!!!");
- }
- else
- {
- front++;
- printf("\n Dequeue Elemen Front ke %d", front);
- }
- }
- void display()
- {
- int i;
- if(front==rear)
- {
- printf("\nAntrian Kosong!!!");
- }
- else
- {
- printf(" \n");
- for(i=front; i<max);i++)
- {
- printf(" | %d ",queue[i]);
- }
- printf("|");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement