Advertisement
Guest User

Untitled

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