Consider the Queue Abstract Data Type (ADT), Q, defined over some generic type T and defined using two stacks, Σ1 and Σ2, where a Stack ADT is implemented as a list, Λ. (Hint: This description implies that the only available operations are those defined for a list.) 1. Define operations Enqueue(Q, T) and Dequeue(Q). 2. (PROGRAMMING) Use Common LISP to define two stacks (stack1 and stack2) as global variables to hold the collection, and implement functions enqueue and dequeue.
Consider the Queue Abstract Data Type (ADT), Q, defined over some generic type T and
defined using two stacks, Σ1 and Σ2, where a Stack ADT is implemented as a list, Λ. (Hint:
This description implies that the only available operations are those defined for a list.)
1. Define operations Enqueue(Q, T) and Dequeue(Q).
2. (PROGRAMMING)
Use Common LISP to define two stacks (stack1 and
stack2) as global variables to hold the collection, and implement functions enqueue
and dequeue.
3. (PROGRAMMING)
Implement operations head, tail and cons in Prolog
and demonstrate their usage. Consider the following example executions:
?- head([a, b, c, d], H).
H = a .
?- head([x], H).
H = x .
?- head([], H).
false.
?- tail([a, b, c, d], T).
T = [b, c, d] .
?- tail([x], T).
T = [] .
?- tail([], T).
false.
?- cons(a, [b, c], NewList).
NewList = [a, b, c] .
?- cons(a, [], NewList).NewList = [a] .
?- cons([], [], NewList).
NewList = [[]] .
Step by step
Solved in 6 steps with 2 images