Linked List push()

Posted by JKid314159 on Stack Overflow See other posts from Stack Overflow or by JKid314159
Published on 2010-04-26T00:58:37Z Indexed on 2010/04/26 1:03 UTC
Read the original article Hit count: 252

Filed under:
|
|
|

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);
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about linked-list