WELCOME TO STMIK MUHAMMDIYAH JAKARTA Website : http://stmikmj.ac.id/site/index.php/id/ |
Assalamualaikum wr.wb
Bissmillahirohmanirohim
Selamat siang pembaca Blogger STMIK MJ. Kali ini saya akan memposting tugas kuliah saya pada :
Mata Kuliah : Struktur Data
Dosen : Fajar Sidik, S.Kom
Tugas : 4
Judul :"Membuat Program QUEUE(ANTRIAN) menggunakan CODEBLOCKS"
Pada postingan kali ini saya akan memposting tugas kuliah membuat program STACK dengan menggunakan software CodeBlocks. Berikut codingan nya, harap disimak baik baik dengan teliti.
#include <iostream>
#include <conio.h>
#include <bits/stdc++.h>
#define MAX 6
using namespace std;
struct Queue
{int data[MAX];
int head;
int tail;
}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("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,data;
Create();
do{
cout<<endl;
cout<<"=============================="<<endl;
cout<<"|| -:: TUGAS QUEUE ::- ||"<<endl;
cout<<"|| PROGRAM BY HAFIF SETIAJI ||" <<endl;
cout<<"|| = -:: MENU PILIHAN::- = ||"<<endl;
cout<<"=============================="<<endl;
cout<<"|| 1. Enqueue. ||"<<endl;
cout<<"|| 2. Dequeue. ||" <<endl;
cout<<"|| 3. Tampil. ||"<<endl;
cout<<"|| 4. Clear. ||"<<endl;
cout<<"|| 5. Keluar. ||"<<endl;
cout<<"=============================="<<endl;
cout<<endl;
cout<<"Masukkan pilihan :"<<endl;
cin>>pil;
switch(pil)
{
case 1:cout<<"Silakan masukkan data = "<<endl;
cin>>data; Enqueue(data);break;
case 2:Dequeue();break;
case 3:Tampil();break;
case 4:Clear();break;
case 5:cout<<"Terimakasih, tekan enter untuk keluar"<<endl;
}
getch(); }
while(pil!=5);}
Catatan :#include <conio.h>
#include <bits/stdc++.h>
#define MAX 6
using namespace std;
struct Queue
{int data[MAX];
int head;
int tail;
}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("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,data;
Create();
do{
cout<<endl;
cout<<"=============================="<<endl;
cout<<"|| -:: TUGAS QUEUE ::- ||"<<endl;
cout<<"|| PROGRAM BY HAFIF SETIAJI ||" <<endl;
cout<<"|| = -:: MENU PILIHAN::- = ||"<<endl;
cout<<"=============================="<<endl;
cout<<"|| 1. Enqueue. ||"<<endl;
cout<<"|| 2. Dequeue. ||" <<endl;
cout<<"|| 3. Tampil. ||"<<endl;
cout<<"|| 4. Clear. ||"<<endl;
cout<<"|| 5. Keluar. ||"<<endl;
cout<<"=============================="<<endl;
cout<<endl;
cout<<"Masukkan pilihan :"<<endl;
cin>>pil;
switch(pil)
{
case 1:cout<<"Silakan masukkan data = "<<endl;
cin>>data; Enqueue(data);break;
case 2:Dequeue();break;
case 3:Tampil();break;
case 4:Clear();break;
case 5:cout<<"Terimakasih, tekan enter untuk keluar"<<endl;
}
getch(); }
while(pil!=5);}
- buka software codeblocks, kemudian pilih file -> new -> empty file
- lalu ketikan atau copy pastekan codingan/skrip diatas
- kemudian simpan dalam format cpp
Berikut hasil tampilan dari program diatas ;
Demikian postingan yang dapat saya bagikan, mohon maaf apabila ada kesalahan penulisan. Terimakasih telah mengunjungi blog saya , semoga bermanfaat...
Wassalamu'alaikum wr.wb