Linked List pop() function
Posted
by JKid314159
on Stack Overflow
See other posts from Stack Overflow
or by JKid314159
Published on 2010-04-23T23:15:10Z
Indexed on
2010/04/23
23:23 UTC
Read the original article
Hit count: 335
Consider the following list:
[LinkNode * head -- LinkNode * node1 -- LinkNode * node2]
I'm creating a stack of FIFO. I Call pop() which I want to pop node1.
LinkNode::LinkNode(int numIn) {
this->numIn = numIn;
next = null;
}
.
.
.
int LinkNode::pop() {
Link * temp = head->next;
head = temp->next;
int popped = head->nodeNum;
delete temp;
Return numOut;
Question:
1) head should be a pointer or a LinkNode *?
2) Link * temp is created on the call stack and when pop finishes doesn't temp delete automatically?
3) My major confusion is on what is the value of temp->next? Does this point to node1.next which equals node2?
Appreciate your help?
My reference is C++ for Java Programmers by Weiss.
© Stack Overflow or respective owner