Author: Stan Eisenstat
Subject: Re: [Cs223] Keeping track of 2 stacks
Date: Monday, 16 Mar 2020, 15:44:46
> Message Posted By: Unknown
...
> I'm having trouble understanding how to implement the deque data
> structure. Since it should consist of 2 stacks, I'm assuming we should be
> creating two stacks in the function createD in Deque.c. However, how do we
> keep track of the tail stack if we may not use global variables, and our
> linked lists must be headless so we can't return both pointers to both
> stacks in a single head element?
Your linked list must be headless, but your Deque may
have a head.
=====
> In addition, i'm confused as to where the code for the case when the H
> stack is empty but the T stack is nonempty belongs in our code. Should
> that also be in isEmptyD (in Deque.c), or is isEmptyD reserved for
> checking whether both H and T are empty?
That code must be invoked by remD() and headD() when
they see that the H stack is empty but the T stack is
not. It could be invoked by isEmptyD() to avoid having
to test whether the T stack is empty.
--Stan-
PREV
INDEX
NEXT