So I have a stack with the typical Push and Pop functions that it allows. I'm having a hard time wrapping my head around how it all actually works code-wise. I saw this post here, Picture/Diagram in the best answer that shows how the list is "pushed" down and you point at the newest element. I have a
node* stack;
which is hooked to a struct "node"
struct node
{
ItemType data;
node* next;
};
How do I incorporate a push and pull with a "node* next;" ? The hard part to wrap my head around is how I'm going to actually do it. I know it initially points at null, and then if I were to push a 2,4,6 it would be 6,4,2,#. Grasping how to actually do it with pointers in a linked list throws me for a loop. I can do it without pointers but the pointers are what get me. Thank you for any help, I really wanna work through this. I'm here to comment back too quickly. Thanks!
EDIT 1: solved - my push is working
EDIT 2: I'm trying to pop now. Would that mean I have to just aim my pointer at the next value? What do I do to the old top node? delete it since I new'd it?
nodethat then points to the old head of the stack (add/remove from the "front").