Advertisement
Samuel_Berkat_Hulu

wewfeaf

May 9th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class Queue_Bank here.
  4.  *
  5.  * Samuel Berkat Hulu
  6.  * @version 5.0 ETS Struktur Data
  7.  */
  8. public class Queue_Bank
  9. {
  10.     private int capacity;
  11.     int queueArr[];
  12.     int front;
  13.     int rear;
  14.     int currentSize = 0;
  15.  
  16.     public Queue_Bank(int sizeOfQueue) {
  17.         this.capacity = sizeOfQueue;
  18.         front = 0;
  19.         rear = -1;
  20.         queueArr = new int[this.capacity];
  21.     }
  22.  
  23.     public void enqueue(int data) {
  24.         if (isFull()) {
  25.         } else {
  26.             rear++;
  27.             if (rear == capacity) {
  28.                 rear = 0;
  29.             }
  30.             queueArr[rear] = data;
  31.             currentSize++;
  32.         }
  33.     }
  34.  
  35.     public void dequeue() {
  36.         if (isEmpty()) {
  37.         } else {
  38.             front++;
  39.             if (front == capacity) {
  40.                 front = 0;
  41.             }
  42.             currentSize--;
  43.         }
  44.     }
  45.  
  46.     public boolean isFull() {
  47.         if (currentSize == capacity) {
  48.             return true;
  49.         }
  50.         return false;
  51.     }
  52.  
  53.     public boolean isEmpty() {
  54.  
  55.         if (currentSize == 0) {
  56.             return true;
  57.         }
  58.         return false;
  59.     }
  60.    
  61.     public int size(){return currentSize;}
  62.    
  63.     public void show(){
  64.         if(isEmpty()){
  65.             System.out.print("Kosong");
  66.             return;
  67.         }
  68.         int i=front;
  69.         while(i<=rear){
  70.             System.out.print(queueArr[i]);
  71.             if(i!=rear) System.out.print(", ");
  72.             i++;
  73.         }
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement