Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Queue_Bank here.
- *
- * Samuel Berkat Hulu
- * @version 5.0 ETS Struktur Data
- */
- public class Queue_Bank
- {
- private int capacity;
- int queueArr[];
- int front;
- int rear;
- int currentSize = 0;
- public Queue_Bank(int sizeOfQueue) {
- this.capacity = sizeOfQueue;
- front = 0;
- rear = -1;
- queueArr = new int[this.capacity];
- }
- public void enqueue(int data) {
- if (isFull()) {
- } else {
- rear++;
- if (rear == capacity) {
- rear = 0;
- }
- queueArr[rear] = data;
- currentSize++;
- }
- }
- public void dequeue() {
- if (isEmpty()) {
- } else {
- front++;
- if (front == capacity) {
- front = 0;
- }
- currentSize--;
- }
- }
- public boolean isFull() {
- if (currentSize == capacity) {
- return true;
- }
- return false;
- }
- public boolean isEmpty() {
- if (currentSize == 0) {
- return true;
- }
- return false;
- }
- public int size(){return currentSize;}
- public void show(){
- if(isEmpty()){
- System.out.print("Kosong");
- return;
- }
- int i=front;
- while(i<=rear){
- System.out.print(queueArr[i]);
- if(i!=rear) System.out.print(", ");
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement