The complete code is as follows:
Package COM. xu. test; import Java. util. authorization; public class p5_1 {/*** @ function: queue operation instance * @ Author: * @ Date: 2012-10-20 */public static void main (string [] ARGs) {sqtype ST = new sqtype (); Data d = NULL; partition input = new partition (system. in); sqtype stack = ST. sqtypeinit (); system. out. println ("Queuing operation:"); system. out. println ("enter the name and age to join the queue:"); do {data Data = new data (); data. name = input. next (); data. age = input. nextint (); If (Data. name. equals ("0") {break; // enter "0", then exit} else {St. insqtype (stack, data) ;}} while (true); string temp = "1"; system. out. println ("team-out operation: Any team-out operation not 0:"); temp = input. next (); While (! Temp. equals ("0") {d = ST. outsqtype (stack); system. out. printf ("the data in the output queue is (% s, % d) \ n", D. name, D. age); temp = input. next ();} system. out. println ("test ended! "); ST. sqtypefree (stack) ;}} class data {string name; int age;} class sqtype {static final int queuelen = 15; data [] DATA = new data [queuelen]; // queue array int head; int tail; @ suppresswarnings ("UNUSED") sqtype sqtypeinit () {sqtype Q; If (q = new sqtype ())! = NULL) {q. head = 0; q. tail = 0; return Q;} else {return NULL;} int sqtypeisempty (sqtype q) // judge that the queue is empty {int temp = 0; If (Q. head = Q. tail) {temp = 1;} return temp;} int sqtypeisfull (sqtype q) // judge if the queue is full {int temp = 0; If (Q. tail = queuelen) return 1; return temp;} void sqtypeclear (sqtype q) // clear the queue {q. head = 0; q. tail = 0;} void sqtypefree (sqtype q) // release the queue {If (Q! = NULL) q = NULL;} int insqtype (sqtype Q, data) // incoming queue {If (Q. tail = queuelen) {system. out. println ("the queue is full! Operation failed! "); Return 0;} else {q. data [q. tail ++] = data; return 1 ;}} data outsqtype (sqtype q) // output queue {If (Q. head = Q. tail) {system. out. println ("the queue is empty. operation failed! "); System. exit (0);} else {return Q. data [q. head ++];} return NULL;} data peeksqtype (sqtype q) // read node data {If (sqtypeisempty (q) = 1) {system. out. println ("Empty queue! "); Return NULL;} else {return Q. data [q. head] ;}} int sqtypelen (sqtype q) // calculate the queue length {int temp; temp = Q. tail-Q. head; return temp ;}}
Running result: