#include <stdio.h>
#include <conio.h>
#include <iostream.h>
typedef struct{
char data[10];
int head;
int tail;
}
Queue;
void keluar();
Queue antrian;
int IsEmpty(){
if (antrian.tail==0)
return 1;
else
return 0;
}
int IsFull(){
if(antrian.tail==10)
return 1;
else return 0;
}
void Enqueue(char data){
if(IsEmpty()==1){
antrian.head=antrian.tail=1;
antrian.data[antrian.tail]=data;
}else
if(IsFull()==0){
antrian.tail++;
antrian.data[antrian.tail]=data;
}
keluar();
}
char Dequeue(){
int i;
char e = antrian.data[antrian.head];
for(i = antrian.head;i<=antrian.tail-1;i++){
antrian.data[i] = antrian.data[i+1];
}
antrian.tail--;
return e;
}
void Tampil(){
clrscr();
if(IsEmpty()==0){
for(int i=antrian.head;i<=antrian.tail;i++){
cout<<antrian.data[i];
}
}else printf("Data kosong!\n");
keluar();
}
void menu()
{
char pil,data;
clrscr();
textcolor(3);
gotoxy(20,14);cprintf(" JUNED/11051103247 \r \n " );
gotoxy(20,5);cprintf (" TUGAS LIMA \r \n " );
gotoxy(20,6);cprintf (" ------------------- \r \n " );
gotoxy(20,7);cprintf (" 1. ENQUEUE \r \n " );
gotoxy(20,8);cprintf (" 2. DEQUEUE \r \n " );
gotoxy(20,9);cprintf (" 3. TAMPIL \r \n " );
gotoxy(20,10);cprintf(" 4. EXIT \r \n " );
cout<<endl;
gotoxy(20,11);cprintf(" Pilihan : "); cin >> pil;
switch(pil)
{
case '1' : clrscr();cout<<" input data : ";cin>>data; Enqueue(data);break;
case '2' : clrscr(); cout<<" data keluar : "<<Dequeue();keluar();
case '3' : Tampil();break;
case '4' : break;
default :
gotoxy(20,3);cprintf(" input anda salah ....!!! ");getch();menu();
}
}
void keluar()
{
char x ;
textcolor(12);
cprintf( "\n Kembali ke Menu ...? (Y/N) "); cin >> x;
switch(x)
{
case 'Y' : menu();break;
case 'y' : menu();break;
case 'N' : cout << " thankzzzz";break;
case 'n' : cout << " thankzzzz";break;
default :
{
cprintf( " input salah ... \r \n");keluar();
}
}
}
void main()
{
menu ();
}
0 komentar:
Posting Komentar