The Potential Method
Deque with stacks size=7 13 S1S1 S2S2 push(x,D): push(x,S 1 ) push(2,D)
Implementation with stacks size= S1S1 S2S2 push(x,D): push(x,S 1 ) push(2,D)
Pop size=8 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D)
Pop size=7 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D) pop(D)
Pop size=6 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D) pop(D)
Pop size=6 S1S1 S2S2 pop(D): if empty?(D) error if empty?(S 1 ) then split(S 2, S 1 ) pop( S 1 ) pop(D) 5 4
Delete from Queue size=5 S1S1 S2S2 4 Pop size=4 S1S1 S2S2 4
The potential method
If then.
PUSH The same for POP without split
S1S1 S2S S1S1 S2S2 5 4 s=6 s/32s/3 POP that calls SPLIT