Stack and Queues with full lists?

Hi, I have a c++ question about stacks and queues pertaining to a full list.

For stack.Push(letter);

http://younginc.site11.com/source/5895/images/fig280%5f01%5f0%2ejpg

and

For queue.Enqueue(letter);

http://younginc.site11.com/source/5895/images/fig287%5f01%5f0%2ejpg

Those are the two sample problems. First off, I think that overFlow would be true in both cases because you are adding data points to already full lists (and underflow would be false in both cases). But I dont understand what the final version would look like since you're not using pop or dequeue, how can the letter be placed in already occupied nodes? I would think the final version would therefore look exactly the same as the first in both cases? (Not counting the true and false). Am I understanding that properly or am I totally off? Someone please help!
Last edited on
We can't possibly know how the state will change if we don't know what the functions do.
Push and Enqueue are just adding new letters to the list (the letter stipulated in the box) in the node position designated by stack.top.
Last edited on
And then? What happens to stack.top?
Well for a stack, the top doesn't change, so its going to remain 2. But that really doesn't pertain to my question, I'm wondering about the .items line, what will be in the nodes (whether they will stay the same "v w x y z") or change. I think it's going to stay the same, but I'm not certain.
Well for a stack, the top doesn't change
Are you totally sure about this? So does that mean I could implement push() like this?
1
2
3
void stack::push(char item){
    this->items[this->front()]=item;
}
I'm sorry, I made a mistake there. IF an item is being added to a stack, the top will increase to the newest item. So if the nodes weren't full it would stack.top would be changed to 3. But does that even take effect if something isn't being added to the list? I would think not, though I am not sure. Which goes back to my previous statement of, the part I am really concerned with is whether the .items line will change.

Edit:
Maybe this could clarify. In the case of:

http://sourcecodemania.com/wp-content/uploads/2012/02/stack-working.jpg

what would happen if instead of using Pop(charStack) on the last line, Push(charStac, 'E') was used instead. But the size of the array was finite and equaled 4.
Last edited on
But does that even take effect if something isn't being added to the list?
Calling push() and "adding something to the list" are one and the same.
I think I see where your confusion is coming from. My advice is that you try to mindlessly run the operation in you head and see what happens.
Well since [2] is already occupied, would it be overwritten with the new letter or would the program be unable to write the new letter in node 2 since it is already occupied?

Found an answer elsewhere online. To answer my previous question there is no change to what the original looks like.
Last edited on
It would be overwritten.

The computer has no built-in notion of free and occupied space. All it sees is space filled with numbers. It's only the way the program treats its data that makes a given space behave as if was free or occupied. In the case of the stack subprogram, items of index <=stack.top are occupied and the rest are empty, regardless of actual content.
Topic archived. No new replies allowed.