bagi teman teman yang ingin belajar tentang QUEUE atau yang membutuhkan scrip QUEUE,di sini telah tersedia scripnya. silahkan di ambil dan di pelajari, semoga bermanfaat bagi teman-teman semuanya.
<em>Ampersands & angle brackets need to be encoded.</em>
#include <stdio.h>
#include <conio.h>
#define MAX 8
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;
}
void Enqueue(int data){
if(IsEmpty()==1){
antrian.head=antrian.tail=0;
antrian.data[antrian.tail]=data;
printf("%d masuk!\n",antrian.data[antrian.tail]);
} else
if(IsFull()==0){
antrian.tail++;
antrian.data[antrian.tail]=data;
printf("%d masuk!\n",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("data 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{
printf("1. Enqueue\n");
printf("2. Dequeue\n");
printf("3. Tampil\n");
printf("4. Clear\n");
printf("5. Exit\n");
printf("Pilihan = ");scanf("%d",&pil);
switch(pil){
case 1: printf("Data = ");scanf("%d",&data);
Enqueue(data);
break;
case 2: printf("Elemen yang keluar : %d\n",Dequeue());
break;
case 3: Tampil();
printf("\n");
break;
case 4: Clear();
break;
}
//getch();
} while(pil!=5);
}
Profile Penulis
Jumlah Pengunjung
PENGUNJUNG BULAN INI
KONTAK KAMI
Friends
Sabtu, 23 Mei 2009
Queue Dalam C++
Translate
Daftar Source Code C++
Category
- C++ (21)
- Instal Windows XP (1)
- jaringan (7)
- Java (14)
- Komputer (12)
- Laptop (10)
- laptop kualitas terbaik (1)
- laptop murah (1)
- materi kul (6)
- Printer (2)
- Router (1)
- Tips and Trick (2)
- Tugas2F (1)
- Tutorial (15)