My Circular Array Queue

  • Uploaded by: bukhori
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View My Circular Array Queue as PDF for free.

More details

  • Words: 174
  • Pages: 2
/** lembar kerja 03, queue*/ public class MyCircularArrayQueue { private T[] theArray; private int front, back, size; public MyCircularArrayQueue() { theArray = (T[]) new Object [10] ; } public MyCircularArrayQueue (int defaultCapacity) { theArray = (T[]) new Object[defaultCapacity]; } public void MakeEmpty() { front = back = size = 0; } public boolean isEmpty() { if(size==0) return true; else return false; } public int getSize() { return size; } public T dequeue() { size--; if(front==theArray.length) { front = 0; } T y = theArray[front]; front++; return y; } public void enqueue (T x) { if(!isFull() && back!=theArray.length) { theArray[back] = x; } else if(back == theArray.length &&!isFull()) { back = 0; theArray[back] = x; } else if(isFull())

{ arrayDoubling(); theArray[back] = x; } else

}

System.out.println("kondisi belom terdeteksi"); back++; size++;

private boolean isFull() { if(size==theArray.length) return true; else return false; } private void arrayDoubling() { T[] thearray = (T[]) new Object[theArray.length * 2]; for (int k=0 ; k < theArray.length ; k++) { thearray[k] = theArray[k]; } theArray = thearray; } }//end clas

Related Documents

Array Circular Queue
April 2020 4
Queue
December 2019 34
Queue
November 2019 15
Array
June 2020 19
Array
November 2019 29

More Documents from ""

Chase Level
June 2020 11
Sda
June 2020 21
Transformator(1).docx
October 2019 12