Вы находитесь на странице: 1из 10

LAPORAN PRAKTIKUM ALGORITMA DAN STRUKTUR DATA MODUL 8

POKOK BAHASAN Queue

Nama NIM DosenPengampu Prodi

Nurul Khoirina 115060801111049 Issa Arwani , S.Kom., M.Sc. Teknik Informatika

Pengesahan Tanggal : Asisten

A. DefinisiMasalah 1. Deskripsi program Program ini adalah program queue yang berarti antrean. Dalam program ini terdapat menu enque, deque, queue front, queue rear, statistik queue, dan destroy. Menu enque digunakan untuk memasukkan data, deque digunakan untuk menghapus data yang pertama kali dimasukkan. Sedangkan queue front adalah data yang terakhir dimasukkan dan queue rear adalah data yang pertama dimasukkan. Untuk menu statistik queue di dalamnya terdapat jumlah data, rata-rata data, data maksimal, dan data minimal. Serta menu destroy digunakan untuk menghapus semua data yang telah dimasukkan ke dalam queue. 2. Pembuatan model : Variable & Tipe Data: Variabel data yang bertipe integer; variabel pointer next, head, tail bertipe node; newNode, del, itr, destroy yang juga bertipe node; variabel count bertipe integer; variabel jumlah, rata, max, dan min bertipe integer; dan variabel pil yang juga bertipe integer Input: Inputan berupa memasukkan data ke dalam queue melalui menu enqueue, dan penghapusan data melalui menu deque, dan destroy Output:

Output berupa tampilan barisan queue, queue front, queue rear, dan statistik queue

B. RancanganAlgoritma

C. Source Code
#include<stdlib.h> #include<stdio.h> #include<conio.h>

typedef struct node node; struct node { int data; //int count;

node *next; };

node *head; node *tail; int count=0; void init(){ head=NULL; tail=NULL; }

int enqueue(){ node *newNode = (node *) malloc(sizeof (node)); if (newNode != NULL) { printf ("Masukkan angka: ");scanf("%d",&newNode->data); if (head == NULL) { head = newNode; } else { tail->next = newNode; } tail = newNode; tail->next = NULL; count++; return 1; }

else { return 0; } }

void dequeue(){ node *del=(node*) malloc (sizeof(node)); del=head; head=del->next; free(del); count--; getch(); }

void display(){ node *itr = head; while (itr != NULL) { printf("\t%d\n", itr->data); itr = itr->next; } }

void destroy(){ node *destroy; while (head != NULL) { destroy = head; head = head->next; free(destroy);

} tail = NULL; count = 0; }

void rear(){ if (head!=NULL){ printf("%d",head->data); } }

void front(){ if (tail!=NULL){ printf("%d",tail->data); } }

void statistik(){ int jumlah=0,rata=0,max,min; node *itr=head; max=itr->data; min=itr->data; do{ jumlah = jumlah+itr->data; if (max<itr->data)max=itr->data; if (min>itr->data)min=itr->data; itr = itr->next; }

while (itr!=NULL); rata=jumlah/count; printf("jumlah: %d\n",jumlah); printf("rata-rata: %d\n",rata); printf("maksimal: %d\n", max); printf("minimal: %d\n", min); }

int main(){ int pil; while (1){ system("cls"); printf("1. Enqueue\n"); printf("2. Dequeue\n"); printf("3. Display\n"); printf("4. Queue Front\n"); printf("5. Queue Rear\n"); printf("6. Statistik Queue\n"); printf("7. Destroy\n"); printf("8. Exit\n"); printf("Pilih salah satu menu diatas: ");scanf("%d",&pil); printf("\n\n"); switch(pil){ case 1: enqueue();break; case 2: dequeue();break; case 3: display();getch();break; case 4: front();getch();break;

case 5: rear();getch();break; case 6: statistik();getch();break; case 7: destroy();getch();break; case 8: exit(0); }

} }

D. Snapshot Program Tampilan menu enque

Tampilan menu display

Tampilan menu queue front

Tampilan menu queue rear

Tampilan menu statistik queue

Вам также может понравиться