Created
April 27, 2021 15:18
-
-
Save wahidabd/833160d86e1a75d0df812bb1b002b307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Queue { | |
private int size; | |
char queueArr[]; | |
int front; | |
int rear; | |
int currentSize = 0; | |
public Queue(int size) { | |
this.size = size; | |
front = 0; | |
rear = -1; | |
queueArr = new char[this.size]; | |
} | |
public void enqueue(char data) { | |
if (!isFull()){ | |
rear++; | |
if (rear == size) { | |
rear = 0; | |
} | |
queueArr[rear] = data; | |
currentSize++; | |
} | |
} | |
public char dequeue() { | |
char fr = 0; | |
if (!isEmpty()){ | |
fr = queueArr[front]; | |
front++; | |
if (front == size) { | |
front = 0; | |
} | |
currentSize--; | |
return fr; | |
} | |
return fr; | |
} | |
public boolean isFull() { | |
if (currentSize == size) { | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment