-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTugas structur data week 5.cpp
118 lines (107 loc) · 2.56 KB
/
Tugas structur data week 5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <iostream>
#include <conio.h>
#define MAX 8
using namespace std;
typedef struct{
int data[MAX];
int head;
int tail;
}Queue;
Queue antrian;
void Create(){
antrian.head=antrian.tail=-1;
}
int IsEmpty(){
if(antrian.tail==-1)
return 1;
else
return 0;
}
int IsFull(){
if(antrian.tail==MAX-1)
return 1;
else
return 0;
}
Enqueue(int data)
{
if(IsEmpty()==1)
{
antrian.head=antrian.tail=0;
antrian.data[antrian.tail]=data;
printf("%d sudah dimasukan",antrian.data[antrian.tail]);
} else
if(IsFull()==0)
{
antrian.tail++;
antrian.data[antrian.tail]=data;
printf("%d sudah dimasukan",antrian.data[antrian.tail]);
}
}
int Dequeue()
{
int i;
int 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 Clear()
{
antrian.head=antrian.tail=-1;
printf("CLEAR");
}
void Tampil()
{
if(IsEmpty()==0)
{
for(int i=antrian.head;i<=antrian.tail;i++)
{
printf(" %d",antrian.data[i]);
}
}else printf("data kosong!\n");
}
main()
{
int pil;
int data;
Create();
do{
cout<<endl<<endl;
cout<<" =============================="<<endl;
cout<<" =\t PROGRAM QUEUE ="<<endl;
cout<<" =============================="<<endl;
cout<<" = 1. Masukkan Antrian = "<<endl;
cout<<" = 2. Panggil Antrian = "<<endl;
cout<<" = 3. Tampil = "<<endl;
cout<<" = 4. Hapus = "<<endl;
cout<<" = 5. Keluar ="<<endl;
cout<<" =============================="<<endl;
cout<<" Masukan Pilihan : ";cin>>pil;
switch(pil)
{
case 1:
cout<<"Masukan Data : ";cin>>data;
Enqueue(data);
break;
case 2:
Dequeue();
break;
case 3:
Tampil();
break;
case 4:
Clear();
break;
case 5:
break;
}
getch();
}
while(pil!=5);
return 0;
}