Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Queue here.
- *
- * @author Samuel Berkat Hulu
- * @version 5.0 21-April-2021
- */
- public class Queue
- {
- private int capacity;
- int front;
- int rear;
- char queueArr[];
- int currentSize = 0;
- public Queue(int sizeOfQueue) {
- this.capacity = sizeOfQueue;
- front = 0;
- rear = -1;
- queueArr = new char[this.capacity];
- }
- public void enqueue(char data) {
- if (!isFull()){
- rear++;
- if (rear == capacity) {
- rear = 0;
- }
- queueArr[rear] = data;
- currentSize++;
- }
- }
- public char dequeue() {
- char fr = 0;
- if (!isEmpty()){
- fr = queueArr[front];
- front++;
- if (front == capacity) {
- front = 0;
- }
- currentSize--;
- return fr;
- }
- return fr;
- }
- public boolean isFull() {
- if (currentSize == capacity) {
- return true;
- }
- return false;
- }
- public boolean isEmpty() {
- if (currentSize == 0) {
- return true;
- }
- return false;
- }
- public String getString(){
- String str = "";
- while(!isEmpty()){
- str = str + dequeue();
- }
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement