Rabu, 29 Mei 2013

PROGRAM QUEU DENGAN FUNGSI DALAM BAHASA C


PROGRAM QUEU DENGAN FUNGSI

#include "stdio.h"
#include "stdlib.h"
#define MAX 5
//tugas yogi
int queue[MAX];
int front = -1;
int rear = -1;
main() {
intpil;
while(1){
printf("\n+-------------------+\n");
printf("|       Menu        |\n");
printf("+-------------------+\n");
printf("| 1. Insert Queue   |\n");
printf("| 2. Delete Queue   |\n");
printf("| 3. Display Queue  |\n");
printf("| 4. Exit           |\n");
printf("+-------------------+\n");
printf("MasukkanPilihan : ");
scanf("%d", &pil);
switch(pil){
case 1 :
insert();
break;
case 2 :
del();
break;
case 3 :
display();
break;
case 4 :
exit(1);
break;
default :
printf("\nInput Salah !"); } } }
insert() {
int add;
if(rear==MAX-1){
printf("Queue Overflow !!!\n");}
else {
if(front==-1)
front = 0;
printf("MasukkanNilaiElemen Queue : ");
scanf("%d",&add);
rear=rear+1;
queue[rear] = add; } }
getch();
del() {
if (front==-1 || front > rear) {
printf("Queue Underflow \n");
return;
  } else {
printf("Element Queue yang di Delete adalah : %d \n", queue[front]);
front=front+1;
getch(); } }
display() {
int i;
if (front == -1){
printf("Queue kosong\n");
}else {
printf("Nilai Element Queue Adalah : ");
for(i=front;i<=rear;i++){
printf("%d",queue[i]);
printf(" ");} }
getch(); }
//tugas yogi

1 komentar: