9 /* Single linked circular lists with queue represented as pointer to rear */
11 queue qinit() /* Initialize empty queue */
17 stack push(q, e) /* Insert element into the queue */
23 p = (stack) ballocate(sizeof(struct queuelem));
24 if (p == NULL) errsignal(RTEMEMOV);
28 p->next = p; /* the lonely element of the queue */
33 p->next = q->next; /* insert at rear */
40 qelem qfront(q) /* Get first element of the queue */
44 fprintf( stderr, "getting first element from empty queue\n");
47 return (q->next->elem);
51 queue qremove(q) /* Remove front element from the queue */
57 fprintf( stderr, "removing first element from empty queue\n");
61 q->next = q->next->next;
62 if (p == q) q = NULL; /* removing last element of the queue */
68 queue qdelete(q, e) /* Delete arbitrary element */
74 if (qempty(q)) return(q);
79 if (p == q) return(q);
93 queue qrotate(q) /* Remove front and insert at rear */
97 fprintf( stderr, "rotating empty queue\n");