/* -*- prolog -*- ****************************************************************************** File: queue.pro Description: The queue ADT. From Luger & Stubblefield. A queue can be represented in Prolog by defining the enqueue() and dequeue() predicates, which take the following form: enqueue(Element, Queue, NewQueue). dequeue(Element, Queue, NewQueue). As in the stack, we use a Prolog list to store the queue's elements. ****************************************************************************** */ empty_queue([]). enqueue(E,[],[E]). enqueue(E,[H|T],[H|TNew]) :- enqueue(E,T,TNew). dequeue(E,[E|T],T). dequeue(E,[E|T],_). %% peek predicate %% Add List to the end of the Queue. add_list_to_queue(List,Queue,NewQueue) :- append(Queue,List, NewQueue). %% append() utility predicate is built-in in some Prologs. append([], List, List). append([Head|TailofList1], List2, [Head|TailofList3]) :- append(TailofList1, List2, TailofList3). %% member() utility predicate is built-in in some Prologs. member(H,[H|T]). member(X,[_|T]) :- member(X,T).