Linked List push()
- by JKid314159
The stack is initialized with a int MaxSize =3. Then I push one int onto the list. " Pushed:" is returned to the console. Program crashes here. I think my logic is flawed but unsure. Maybe an infinite loop or unmet condition? Thanks for your help.
I'm trying to traverse the list to the last node in the second part of the full() method. I implemented this stack as array based so must implement this method full() as this method is inside of main class.
while(!stacker.full()) {
cout << "Enter number = ";
cin >> intIn;
stacker.push(intIn);
cout << "Pushed: " << intIn << endl;
}//while
Call to LinkListStack.cpp to class LinkList full().
int LinkList::full() {
if(head == NULL) {
top = 0;
} else {
LinkNode * tmp1;
LinkNode * tmp2;
tmp1 = head;
while(top != MaxSize) {
if(tmp1->next != NULL){
tmp2 = tmp1->next;
tmp1 = tmp2;
++top;
}//if
}//while
}//else
return (top + 1 == MaxSize);
}