Algorithm 2 Double Ended Queue
Require: is an array of length indexed from with two attributes and initialized to be
Ensure: Implementation of deque operations that handle overflow and underflow
1: // Inserts elements to the front of deque.
2:procedure HeadEnqueue()
3:if QueueFull() then
4:error "overflow"
5:else
6:if then
7:
8:else
9:
10:
11:end if
12:end if
13:end procedure
14:
15: // Inserts elements to the back of deque.
16:procedure TailEnqueue()
17:if QueueFull() then
18:error "overflow"
19:else
20:
21:if then
22:
23:else
24:
25:end if
26:end if
27:end procedure
28:
29: // Deletes elements from the front of deque.
30:procedure HeadDequeue()
31:if QueueEmpty() then
32:error "underflow"
33:else
34:
35:if then
36:
37:else
38:
39:end if
40:return
41:end if
42:end procedure
43:
44: // Deletes elements from the back of deque.
45:procedure TailDequeue()
46:if QueueEmpty() then
47:error "underflow"
48:else
49:if then
50:
51:else
52:
53:end if
54:return
55:end if
56:end procedure