class Queue { //fronta pro znaky s privátními elementy private char q[]; // array pro umístění fronty private int putloc, getloc; //indexy vložení,výběru Queue(int size) { q = new char[size+1]; //alokace paměti pro frontu putloc = getloc = 0; } // Put znak do fronty void put(char ch) { if(putloc==q.length-1) { System.out.println(" fronta je plna."); return; } putloc++; q[putloc] = ch; } // Get znak z fronty. char get() { if(getloc == putloc) { System.out.println(" Fronta je prazdna."); return (char) 0; } getloc++; return q[getloc]; } } class QDemo { public static void main(String args[]) { Queue bigQ = new Queue(100); Queue smallQ = new Queue(4); char ch; int i; System.out.println("uziti bigQ k uloz. abecedy"); // vloz do bigQ for(i=0; i < 26; i++) bigQ.put((char) ('A' + i)); // vybrani a zobrazeni elementu z bigQ System.out.print("Obsah bigQ: "); for(i=0; i < 26; i++) { ch = bigQ.get(); if(ch != (char) 0) System.out.print(ch); } System.out.println("\n"); System.out.println("uziti smallQ ke gener.preplneni"); for(i=0; i < 5; i++) { System.out.print("Pokus o ulozeni " + (char) ('Z' - i)); smallQ.put((char) ('Z' - i)); System.out.println(); } System.out.println(); // další chyby System.out.print("Obsah smallQ: "); for(i=0; i < 5; i++) { ch = smallQ.get(); if(ch != (char) 0) System.out.print(ch); } } }