Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. class CircularQueue implements ICharQ {
  2.     private char q[];
  3.     private int putloc, getloc;
  4.  
  5.     public CircularQueue(int size) {
  6.         q = new char[size+1];
  7.         putloc = getloc = 0;
  8.     }
  9.  
  10.     public void put(char ch) {
  11.         if (putloc+1==getloc |
  12.                 ((putloc==q.length-1) & (getloc==0))) {
  13.             System.out.println(" - Queue if full.");
  14.         }
  15.  
  16.         q[putloc++] = ch;
  17.         if (putloc==q.length) putloc = 0;
  18.     }
  19.  
  20.     public char get() {
  21.         if (getloc == putloc) {
  22.             System.out.println(" - Queue is empty");
  23.             return (char) 0;
  24.         }
  25.  
  26.         char ch = q[getloc++];
  27.         if (getloc==q.length) getloc = 0;
  28.         return ch;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement