DIG1G3 Implementasi Struktur Data

dokumen-dokumen yang mirip
BAB IV Antrian(Queue)

DIG1G3 Implementasi Struktur Data

DIG1G3 Implementasi Struktur Data

ARNA FARIZA YULIANA SETIOWATI

05. Double Linked List

BAB VIII QUEUE (ANTRIAN)

MODUL PRAKTIKUM STRUKTUR DATA DAN ALGORITMA QUEUE

Algoritma Pemrograman & Struktur Data

Queue Priority Queue STRUKTUR DATA. JULIO ADISANTOSO Departemen Ilmu Komputer IPB. Pertemuan 6 : 7 Juli 2015

A. TUJUAN PEMBELAJARAN

TIF 4201 Algoritma Dan Struktur Data

STACK atau TUMPUKAN. Pertemuan 5 STACK (TUMPUKAN)

Algoritma dan Struktur Data. Pertemuan 7 Linked List

04. Single Linked List

LAPORAN PRAKTIKUM RESMI QUEUE

IX. Implementasi ADT : Stacks & Queues. Operasi dasar Contoh kegunaan Implementasi Array-based dan linked list-based

Masukan Judul... Infotype àsebuah tipe terdefinisi yang menyimpan informasi sebuah elemen list

Praktikum 5. Antrian (Queue)

Algoritma dan Struktur Data. Queue

BAB III QUEUE (ANTRIAN)

Data Structure STRUKTUR DATA QUEUE. Chapter 3. Dahlia Widhyaestoeti, S.Kom

(3) BAHAN KAJIAN (materi ajar)

Algoritma dan Struktur Data. Pertemuan 9 Circular Linked List

Algoritma Dan Struktur Data II

Linked List 6.3 & 7.3 NESTED LOOP

Implementasi Queue menggunakan Array. Imam Fahrur Rozi

KONSEP POINTER DAN LINKED LIST

Algoritma dan Struktur Data. Linked List

MODUL PRAKTIKUM STRUKTUR DATA DAN ALGORITMA LINKED LIST (BAGIAN 2)

Algoritma Pemrograman [BS204]

SENARAI BERANTAI (LINK LIST)

KUM 3 IMPLEMENTASI LIST

Review. Struktur Data & Algoritme (Data Structures & Algorithms) Objectives. Outline. Stacks & Queues

STRUKTUR DATA POKOK BAHASAN - 7 STACK ( TUMPUKAN )

QUEUE (ANTREAN) Operasi Antrean : FIFO (First In First Out) Elemen yang pertama masuk merupakan elemen yang pertama keluar.

ALGORITMA DAN STRUKTUR DATA

PRAKTIKUM STRUKTUR DATA QUEUE. SULIDAR FITRI, M.Sc

STRUKTUR DATA POKOK BAHASAN - 8 QUEUE ( ANTRIAN)

UJIAN AKHIR SEMESTER GANJIL 2005/2006 ALGORITMA & STRUKTUR DATA / CS2014

Algoritma dan Struktur Data. Pertemuan 8 Doubly Linked List

Senarai berantai. linked list. Pertemuan keenam Struktur data st3telkom.ac.id. by : tenia wahyuningrum & Sisilia Thya Safitri

Data structure :Metode LINK LIST. Kusnawi, S.Kom, M.Eng STMIK AMIKOM Yogyakarta

ARNA FARIZA YULIANA SETIOWATI

Struktur Data Array. Rijal Fadilah S.Si

QUEUE (ANTREAN) Prinsip Antrean : FIFO (First In First Out) FCFS (First Come First Serve) Yang Tiba lebih awal Maka akan dilayani Terlebih Dahulu

PERTEMUAN KE-6. Pertemuan 6

QUEUE Antrian 1. DEFINISI

Politeknik Elektronika Negeri Surabaya

MODUL PRAKTIKUM STRUKTUR DATA DAN ALGORITMA STACK

DIG1G3 Implementasi Struktur Data

Pertemuan 3. Perubah Dinamis (Dinamic variable) Suatu perubah yang akan dialokasikan hanya pada saat diperlukan, yaitu setelah program dieksekusi.

List Linier (Bag. I) IF2121/Algoritma dan Struktur Data Sem. I 2016/ /25/2017 IF2121/Sem I 2017/2018 1

TIPE DATA ABSTRAK MENGGUNAKAN BAHASA C

DOUBLE LINKED LIST. Danang Wahyu Utomo Danang Wahyu Utomo, M.Kom, M.CS

Struktur Data & Algoritme (Data Structures & Algorithms)

Algoritma Dan Struktur Data II

Struktur Data. Tumpukan : Definisi & Operasi. Pertemuan 4 PROBLEM ALGORITHM DATA IMPLEMENTATION. Pert. 4b Struktur Data - FMIPA USD

SINGLE LINKED LIST (NON CIRCULAR)

QUEUE (ANTRIAN) Depan=1 Belakang=

Algoritma Dan Struktur Data II. Queue

LIST. Dewi Sartika, M.Kom

Struktur Data dan Algoritma

KONSEP POINTER DAN LINKED LIST

KONSEP POINTER DAN LINKED LIST

KONSEP POINTER DAN LINKED LIST

*Sekumpulan elemen yang diatur secara terurut. *Linear List tidak sama dengan Connected-List

STL DLL STRUKTUR DATA. JULIO ADISANTOSO Departemen Ilmu Komputer IPB. Pertemuan 3 : 29 Juni 2015

KONSEP POINTER DAN LINKED LIST

Single Linked List (1)

KKKF33110 STRUKTUR DATA

POINTER STACK DAN QUEUE. Institut Teknologi Sumatera

Algoritma dan Struktur Data. Ramos Somya, S.Kom., M.Cs.

Integer (Bilangan Bulat) Yang dimaksud bilangan bulat adalah, -1, -2, -3, 0, 1, 2, 3, 4 dan lain lain yang bukan merupakan bilangan pecahan.

DIKTAT KULIAH ALGORITMA dan STRUKTUR DATA II. : Mahasiswa mampu menjelaskan teknik pemrograman menggunakan Queue.

STRUKTUR DATA Pertemuan 1 s.d 8

REPRESENTASI FISIK LIST LINEAR

MODUL PEMROGRAMAN 2. Queue (Antrian)

PRAKTIKUM ALGORITMA DAN STRUKTUR DATA MODUL KE-2 STACK DAN QUEUE

IMPLEMENTASI ANTRIAN DENGAN MENGGUNAKAN ARRAY

BAB IV QUEUE ATAU ANTREAN

STL DLL STRUKTUR DATA. JULIO ADISANTOSO Departemen Ilmu Komputer IPB. Pertemuan 3 : 27 Juni 2016

STRUKTUR DATA Pertemuan 6

MODUL 6 SINGLE & DOUBLE LINKED LIST

Algoritma dan Struktur Data. Ramos Somya

KUM 5 IMPLEMENTASI QUEUE

Algoritma Pemrograman & Struktur Data

5. QUEUE (ANTRIAN) TUJUAN PRAKTIKUM

Struktur Data. Queue (Antrian)

MAKALAH STRUKTUR DATA. DOSEN PEMBIMBING Nisa miftachurohmah, S.kom., M.Si PENYUSUN SITI JAMILATUL MU ADDIBAH ( )

MODUL PRAKTIKUM STRUKTUR DATA DAN ALGORITMA LINKED LIST (BAGIAN 1)

Review : Sifat Implementasi Linear List dengan Array

Algoritma dan Struktur Data. Ramos Somya

PERTEMUAN KE 11. Linked List. Apa Itu Linked List?

SOAL C++ Created by Yuli Astuti,S.Kom Copyright 2009

1. Traversing Untuk algoritma traversing sama seperti pada single Link List

LAPORAN PRAKTIKUM IV. Oleh:

BAB 2 LANDASAN TEORI

QUEUE (ANTRIAN) Struktur Data - Queue

Kode : IF2121 NIM :... Matakuliah : Algoritma dan Struktur Data Nama :... Hari, Tanggal : Senin, 13 November 2017 Waktu : 150 Menit

LOGO STRUKTUR DATA QUEUE

Transkripsi:

DIG1G3 Implementasi Struktur Data Program Studi Diploma III Teknik Informatika Fakultas Ilmu Terapan Telkom University Dosen: Cahyana, S.T., M.Kom. Indra Azimi, S.T., M.T.

2 Apa yang dimaksud queue? Apa kegunaan queues? Properti apa saja yang dimiliki queues? Bagaimana implementasinya?

3 Apa yang dimaksud queue? Queue adalah list yang memiliki aturan main dalam proses inserted dan removed data. Konsep queue adalah FIFO (first in first out) Insertion/Enqueue atau penambahan data hanya dilakukan di salah satu ujung list (rear) dan deletions/dequeue hanya dilakukan di ujung lainnya (front) Queue menyerupai sebuah antrian dalam dunia nyata

4 Apa kegunaan queue? Mengatur layanan terhadap suatu task dalam suatu sistem agar tercipta fair treatment client-server systems operating systems: antrian task, contoh antrian untuk mencetak (printing). simulation and modeling: contoh air traffic control, urban transport.

5 Queue ADT Operasi yang mungkin ada pada Queue: 1. Inisialisasi queue Q menjadi empty queue. 2. Menentukan sebuah queue kosong atau tidak, Q, is empty. 3. Menentukan sebuah queue penuh atau tidak, Q, is full. 4. Jika Q tidak penuh, sisipkan item baru pada ujung belakang (rear) queue, Q. 5. Jika Q tidak kosong, hapus sebuah item pada ujung depan (front) queue, Q.

6 Queue ADT interface /* File: Queue.h */ #define MAXQUEUESIZE 100 struct Queue int Count, Front, Rear; char Items[MAXQUEUESIZE]; ; /* Defined Operations */ Queue *QueueNew (); /* Initialize the queue Q to be the empty queue. */ int QueueEmpty ( Queue *Q ); /* Returns 1 (True) if (and only if) the queue Q is empty*/ int QueueFull ( Queue *Q ); /* Returns 1 (True) if (and only if) the queue Q is full */ void QueueInsert (char R, Queue *Q ); /* If Q is not full, insert new item R onto the end of Q */ void QueueRemove ( Queue *Q, char *F ); /* If Q is not empty, remove its first item, put it in F. */

7 Implementasi Queue Untuk representasi sekuensial menggunakan array:

8 Queues dengan Circular Track

9 Queues dengan Circular Track Bagaimana implementasi dalam program? Menggunakan linear array berukuran N. Menggunakan modular arithmetic: ekspresi X % N menghasilkan nilai X tetap dalam range 0..N-1. Set Rear: tambahkan nilai rear lama dengan 1; jika rear=n, set dengan 0. Rear = (Rear + 1) % N; Hal yang sama untuk Front: Front = (Front + 1) % N;

10 Sequential Queue Representation (I) Definisikan MAXQUEUESIZE sebagai konstanta. Sebuah queue merupakan struct yang mengandung: number of items pada queue sebagai Count member Array item queue sebagai Items member Array indeks (Front) Array indeks (Rear) File Queue.c berisi definisi dan operasi QueueNew, QueueEmpty, QueueFull, QueueInsert dan QueueRemove (slide sebelumnya)

11 Sequential Queue Representation (I) Initialization: inisialisasi queue Q menjadi queue kosong. sebuah queue disebut empty jika Count =0. Count diset = 0. indeks Front diset = 0. indeks Rear diset = 0.

12 Sequential Queue Representation /* Initialize the queue Q to be the empty queue. */ Queue * QueueNew () Queue *Q = new Queue; Q->Count = 0; Q->Front = 0; Q->Rear = 0; return Q ;

13 Sequential Queue Representation Empty test: menentukan sebuah queue kosong atau tidak, Q, is empty. Sebuah queue didefinisikan empty jika Count =0. /* Returns 1 (True) if (and only if) * the queue Q is empty. */ int QueueEmpty ( Queue *Q ) return ( Q->Count == 0 );

14 Sequential Queue Representation Full test: menentukan sebuah queue penuh atau tidak, Q, is full. sebuah queue didefinisikan full jika Count = MAXQUEUESIZE. /* Returns 1 (True) if (and only if) * the queue Q is full. */ int QueueFull ( Queue *Q ) return ( Q->Count == MAXQUEUESIZE );

15 Sequential Queue Representation Insert a new item onto the rear of the queue, Q. /* If Q is not full, insert a new item R onto rear of Q by: * 1. storing R in the item array at position Rear; * 2. incrementing Rear by one (WRAP AROUND!); * 3. incrementing Count by one. */ void QueueInsert (char R, Queue *Q) if (Q->Count == MAXQUEUESIZE) cout<<"insert:not allowed on full queue. <<endl; else Q->Items[Q->Rear] = R; Q->Rear = (Q->Rear + 1) % MAXQUEUESIZE; Q->Count++;

16 Sequential Queue Representation Jika queue Q is not empty, remove sebuah item dari front sebuah Q. /* If Q is not empty, remove first item and put it in F by: * 1. taking F from the item array at position Front; * 2. incrementing Front by one (WRAP AROUND!); * 3. decrementing Count by one. */ void QueueRemove ( Queue *Q, char *F ) if ( Q->Count == 0 ) cout<< REMOVE:Not allowed on empty q. <<endl; else *F = Q->Items [Q->Front]; Q->Front = (Q->Front + 1) % MAXQUEUESIZE; Q->Count--;

17 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main () Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Orang lain dapat menulis kode di atas tanpa mengetahui bagaimana queue tersebut diimplementasikan.

18 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: Empty

19 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: a

20 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: a, b

21 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: a, b, c

22 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: b, c Print: Just got: a.

23 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: c Print: Just got: b.

24 Using the Queue interface #include "QueueInterface.h" /* Assume ItemType is char.*/ /* Access operations and types for stacks.*/ int main ( void ) Queue *tq; /* Variable TestQueue of type Queue. */ char C; tq = QueueNew ( ); /* Make tq empty. */ QueueInsert ( a, tq ); QueueInsert ( b, tq ); QueueInsert ( c, tq ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueRemove ( tq, &C ); printf ( "Just got: %c.\n", C ); QueueInsert ( d, tq );... Queue: c, d

25 Linked Queue Representations Representasi berikut menggunakan pointer pada front dan rear. Setiap node terdiri atas item queue yaitu item member dan links ke node berikutnya pada list, menggunakan pointer pada link member.

26 Linked Queue Implementation Conditional checks untuk kondisi tertentu pada linked queue implementation:

27 Linked Queue Representations /*File: queuetypes.h*/ typedef struct tqueuenode char item; tqueuenode *address; QueueNode; typedef struct tqueue QueueNode *front; QueueNode *rear; Queue;

28 Linked Queue Implementation #include QueueInterface.h /*Initialize the queue Q to be the empty queue*/ void InitializeQueue(Queue *Q) Q->front=NULL; Q->rear=NULL;

29 Linked Queue Implementation Empty test: menentukan sebuah queue kosong atau tidak, Q, is empty. Sebuah queue didefinisikan empty jika front = NULL. boolean Empty(Queue *Q) return (Q->front==NULL);

30 Linked Queue Implementation Full test: menentukan sebuah queue penuh atau tidak, Q, is full. boolean Full(QueueNode *nb) return (nb==null);

31 Linked Queue Implementation Insert item baru ke ujung rear suatu queue, Q. void Insert(char R, Queue *Q) QueueNode *temp = new QueueNode; if (Full(temp)) systemerror( system storage is exhausted ) else temp->item = R; temp->address=null; if (Q->rear==NULL) Q->front=temp; Q->rear=temp; else Q->rear->address=temp; Q->rear=temp;

32 Linked Queue Implementation Terdapat Q tidak kosong, remove sebuah item dari front sebuah queue Q. void remove(queue *Q, char *F) QueueNode *temp; if (Q->front==NULL) systemerr( attempt to remove item from empty queue ); else *F=Q->front->item; temp=q->front; Q->front=temp->address; free(temp); if (Q->front==NULL) Q->rear=NULL;

33 Queue Applications Queues pada operating systems Menggunakan queues sebagai memory buffers Queues pada simulation experiments Clients - servers Simulating supermarket checkout lines

34 References Lectures stacks and queues. Dept of Computer Science, University of Bristol, 2004 Thomas A. Standish, Data Structures, Algorithms & Software Principles in C Addison- Wesley, 1995 p. 253 ff (Chapter 7) Tjokorda Agung Budi Wirayuda, PI1043 Struktur Data: Queue Data Structure.