Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment