KODE PROGRAM QUEUE TIPE DATA INTEGER & STRING
QUEUE INTEGER &
STRING
#include
#include
typedef struct
{
int nama[10][10];
int nim[10];
int progdi[10][10];
int head,tail;
}QUEUE;
QUEUE antrian;
void main()
{
antrian.head=antrian.tail=-1;
int pilihan,i;
do
{
system("cls");
printf ("1.Enque
data mahasiswa\n");
printf ("2.Deque
data mahasiswa\n");
printf ("3.Print
data mahasiswa\n");
printf ("4.Clear
data mahasiswa\n");
printf ("5.Keluar\n");
printf ("\nPilihan=
");
scanf ("%d",&pilihan);
switch(pilihan)
{
case 1 :
{
if (antrian.tail==10-1)
{
printf("Antrian penuh");
getch ();
}
else
{
antrian.tail++;
printf("NIM mahasiswa =
");
scanf("%d",&antrian.nim[antrian.tail]);
printf("Nama mahasiswa
= ");
scanf("%s",&antrian.nama[antrian.tail]);
printf("Progdi mahasiswa
= ");
scanf("%s",&antrian.progdi[antrian.tail]);
}
getch();
break;
case 2 :
{
if (antrian.tail==-1)
{
printf("Antrian kosong");
getch();
}
else
{
printf("Data mahasiswa yang akan
di deque bernama = %s",antrian.nama[antrian.head+1],10);
for(i=antrian.head;i<=antrian.tail-1;i++)
{
antrian.nim[i]=antrian.nim[i+1];
antrian.nama[i][10]=antrian.nama[i+1][10];
antrian.progdi[i][10]=antrian.progdi[i+1][10];
}
antrian.tail--;
getch();
}
break;
}
case 3 :
{
if (antrian.tail==-1)
{
printf("Antrian kosong");
getch ();
}
else
{
printf("NIM
Nama Progdi \n");
for (i=0;i<=antrian.tail;i++)
{
printf("%d
",antrian.nim[i]);
printf("%s
",antrian.nama[i]);
printf("%s
",antrian.progdi[i]);
printf("\n");
}
getch ();
}
break;
}
case 4 :
{
antrian.tail=-1;
printf("Data sudah terhapus
semua");
getch();
}
break;
case 5 :
break ;
default :
{
printf("Maaf pilihan yang anda
masukkan tidak ada");
}
}
}
}
while (pilihan<5);
getch ();
}
0 komentar:
Posting Komentar