00:01
All right, for this question, we're asked to describe how to implement the stack adt using a single q as an instance variable and only constant additional local memory within the method bodies.
00:12
What is the running time of the push, pop, and top methods for your design? so, essentially, we can represent a stack using a q.
00:28
So i said the front of the queue is the top of the stack, and the back of the queue is the bottom of the stack.
00:33
Stack.
00:35
So what i mean by this is we'll have a public class with the stack, generic type of e.
00:51
And essentially we call that inside, we'll have a private queue that we'll be referring to as q.
01:01
And then in here we could add our constructors and then getters and setters, size, etc.
01:10
So that's just pretty generic.
01:12
They will all use the q's methods to return.
01:15
So keep that in mind.
01:18
And then we'll write the method push will be implemented in such a way that an entry is on -kewed, and then the d -qed element, and then on -keyed them in a loop until we have given entry in the front of the q.
01:30
So this will take over in time to run.
01:32
So what i mean by that is void push, right? we'll be reworking the push to work with on queue so we'll say q...