//pretezovane konstruktory class Queue { private char q[]; // pole pro ulozeni fronty private int putloc, getloc; // indexy pro vloz/vyber // 1.konstruktor fronty delky size Queue(int size) { q = new char[size+1]; // alokace mista pro frontu putloc = getloc = 0; } // 2.konstr. fronty dle fronty Queue(Queue ob) { putloc = ob.putloc; getloc = ob.getloc; q = new char[ob.q.length]; //kopirovani prvku for(int i=getloc+1; i <= putloc; i++) q[i] = ob.q[i]; } // 3.konstr.inicializuje frontu polem Queue(char a[]) { putloc = 0; getloc = 0; q = new char[a.length+1]; for(int i = 0; i < a.length; i++) put(a[i]); } // metoda pro vlozeni void put(char ch) { if(putloc==q.length-1) { System.out.println(" -- fronta je plna"); return; } putloc++; q[putloc] = ch; } // metoda pro vyber char get() { if(getloc == putloc) { System.out.println(" -- fronta je prazdna."); return (char) 0; } getloc++; return q[getloc]; } } // Hlavni program class QDemo { public static void main(String args[]) { // vytvoreni prazdne fronty pro 10 mist Queue q1 = new Queue(10); char name[] = {'E', 'v', 'a'}; // vytvoreni fronty z pole Queue q2 = new Queue(name); char ch; int i; // vlozeni znaku do q1 for(i=0; i < 10; i++) q1.put((char) ('A' + i)); // konstrukce fronty z jine fronty Queue q3 = new Queue(q1); // Vypis obsahu System.out.print("Obsah q1: "); for(i=0; i < 10; i++) { ch = q1.get(); System.out.print(ch); } System.out.println("\n"); System.out.print("Obsah q2: "); for(i=0; i < 3; i++) { ch = q2.get(); System.out.print(ch); } System.out.println("\n"); System.out.print("Obsah q3: "); for(i=0; i < 10; i++) { ch = q3.get(); System.out.print(ch); } } }