Sie sind auf Seite 1von 11

UNIVERSITAS KRISNADWIPAYANA

STRUKTUR DATA

DISUSUN OLEH :

MUHAMMAD RIZKI AKBAR

1670231060
SCRIPT DATA STUCK

#include <iostream>

#include <stdio.h>

#include <conio.h>

using namespace std;

main()

int stack[10];

int top=-1;

int pilih,i;

do

cout<<"\t============ MENU ============"<<endl<<endl;

cout<<"\t======================================"<<endl;

cout<<"\t1. PUSH "<<endl;

cout<<"\t2. POP "<<endl;

cout<<"\t3. VIEW "<<endl;

cout<<"\t4. EXIT "<<endl;

cout<<"\t======================================"<<endl;

printf("Pilih = "); scanf("%d", &pilih);

switch(pilih)

case 1://push

system("cls");

if (top>=9)

printf("stack penuh Bro!!\n");


else

printf("Data ="); scanf("%d",&stack[top+1]);

top++;

break;

case 2://pop

system("cls");

if (top<0)

printf("stack kosong bro!\n");

else

printf("Data Keluar = %d\n", stack[top]);

top--;

break;

case 3://view

cout<<"\n\nData yang ada pada stack :\n";

for(i=top; i>=0; i--)

printf("%d", stack[i]);

printf("\n");

break;

case 4:

printf("Exit_\n");
break;

while(pilih!=4);

}
SCRIPT PROGRAM QUEUE

#include <stdio.h>

#include <conio.h>

#include <iostream>

#define MAX 6

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;

void enqueue(int data)

if(isempty()==1)

antrian.head=antrian.tail=0;

antrian.data[antrian.tail]=data;

printf("%d, Sudah Masuk!",antrian.data[antrian.tail]);

void tampil();

int i;

if (isempty()==0)

for(i=antrian.head;i<=antrian.tail;i++)

printf(" %d ",antrian.data[i]);

else

printf("\n**** QUEUE IS EMPTY ****\n");

else
if(isfull()==0)

antrian.tail++;

antrian.data[antrian.tail]=data;

printf("%d , Sudah Masuk!",antrian.data[antrian.tail]);

else{

if(isfull()==1)

cout<<"\n\n**** QUEUE IS FULL , data TIDAK dapat masuk **";

cout<<"PRESS any key for back to MENU";

int dequeue()

if (isempty()==1){

cout<<"\n**** ERROR :: QUEUE IS EMPTY **";

}else

if(isempty()==0){

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--;
cout<<"\n\nData Yang Keluar => "<<e;

cout<<"PRESS any key for back to MENU";

void clear()

antrian.head=antrian.tail=-1;

printf("\n\n**** DATA CLEAR **");

cout<<"PRESS any key for back to MENU";

void tampil()

int i;

if(isempty()==0)

cout<<"Data Yang ada Dalam QUEUE : "<<endl<<endl;

for(i=antrian.head;i<=antrian.tail;i++)

printf("| %d |",antrian.data[i]);

else

printf("\n**** QUEUE IS EMPTY ****\n");

cout<<"PRESS any key for back to MENU";

}
int main()

int pil;

int data;

create();

do

system ("cls");

cout<<"======== MENU PILIHAN ========"<<endl;

cout<<"MUHAMMAD RIZKI AKBAR"<<endl;

cout<<"1670231060"<<endl;

cout<<"Teknik Informatika"<<endl;

cout<<"============================"<<endl;

cout<<" 1. ENQUEUE "<<endl;

cout<<" 2. DEQUEUE "<<endl;

cout<<" 3. TAMPILAN "<<endl;

cout<<" 4. CLEAR "<<endl;

cout<<" 5. KELUAR "<<endl;

cout<<"============================"<<endl;

cout<<" Masukan Pilihan Anda -> ";cin>>pil;

switch(pil){

case 1:

system ("cls");

printf("\n\n Masukan Data -> "); scanf("%d",&data);

enqueue(data);

break;
case 2:

system ("cls");

dequeue();

break;

case 3:

system ("cls");

cout<<endl;

tampil();

break;

case 4:

system ("cls");

clear();

break;

case 5:

system ("cls");

cout<<"** TERIMA KASIH **"<<endl;

break;

getch();

} while(pil!=5);