1 / 14

QUEUE (Antrian)

QUEUE (Antrian). Definisi. Queue = antrian Data yang pertama masuk dalam antrian, akan keluar terlebih dahulu. Jenis-jenis Queue : Linear Queue Double Ended Queue (Dequeue). Q[10]. 5. 0. 7. 3. 9. 2. 1. 8. 4. 6. x. x. x. x. R. F. 6. 3. R. F. X.

Download Presentation

QUEUE (Antrian)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. QUEUE (Antrian)

  2. Definisi • Queue = antrian • Data yang pertama masuk dalam antrian, akan keluar terlebih dahulu. • Jenis-jenis Queue : • Linear Queue • Double Ended Queue (Dequeue)

  3. Q[10] 5 0 7 3 9 2 1 8 4 6 x x x x R F 6 3 R F X Linear Queue (Antrian Lurus) • Ilustrasi Antrian Lurus Keterangan : F = Front (depan) R = Rear (belakang) F menunjuk pengantri paling depan, yaitu pengantri yg siap dilayani. R menunjuk pengantri paling belakang, yaitu pengantri yg paling terakhir masuk.

  4. Proses dlm Antrian Lurus • Prinsip / Konsep Proses : • FIFO (First In First Out) • FIFS (First In First Serve) • Proses : • AWAL (Inisialisasi) • INSERT (Sisip, Masuk, Simpan, Tulis) • DELETE (Hapus, Keluar, Ambil/Dilayani, Baca) • RESET (Kembali ke AWAL)

  5. Kondisi Antrian Lurus

  6. Algoritma Lengkap INSERT • Periksa apakah Antrian BISA DIISI if ( R < n – 1) { R = R + 1; Q[R] = x; } else cout<<“Antrian Penuh”;

  7. Algoritma Lengkap DELETE • Periksa apakah Antrian ADA ISINYA if ( F < R + 1) { x = Q[F]; F = F + 1; if ((F=R+1) && (R=n-1)) { F = 0; R = -1; } } else cout<<“Antrian Kosong”;

  8. 0 3 5 7 2 9 1 4 6 8 x x x x R L Double Ended Queue (Deque) • Ilustrasi Deque (Antrian dengan Ujung Ganda) Insert Kiri Insert Kanan Q[10] Delete Kiri Delete Kanan Keterangan : L = Left (kiri) R = Right (kanan) L menunjuk pengantri yg terakhir masuk di sebelah kiri dan siap dilayani. R menunjuk pengantri yg terakhir masuk di sebelah kanan dan siap dilayani.

  9. Proses dlm Deque • Prinsip / Konsep Proses : • bukan FIFO, bukan juga LIFO, tergantung kesempatan yang ada. • Proses : • AWAL (Inisialisasi) • INSERT (Sisip, Masuk, Simpan, Tulis) • DELETE (Hapus, Keluar, Ambil/Dilayani, Baca)

  10. Kondisi Deque

  11. Algoritma Lengkap INSERT KIRI • Periksa apakah Deque BISA DIISI DARI KIRI void INSERT_KIRI() { if ( L > 0) { L = L - 1; Q[L] = x; } else cout<<“Antrian Kiri Penuh”; }

  12. Algoritma Lengkap INSERT KANAN • Periksa apakah Deque BISA DIISI DARI KANAN void INSERT_KANAN() { if ( R < n - 1) { R = R + 1; Q[R] = x; } else cout<<“Antrian Kanan Penuh”; }

  13. Algoritma Lengkap DELETE KIRI • Periksa apakah Deque ADA ISINYA void DELETE_KIRI() { if (L < R + 1) { x = Q[L]; L = L + 1; } else cout<<“Antrian Kosong”; }

  14. Algoritma Lengkap DELETE KANAN • Periksa apakah Deque ADA ISINYA void DELETE_KANAN() { if (L < R + 1) { x = Q[R]; R = R - 1; } else cout<<“Antrian Kosong”; }

More Related