Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

linked list stack

linked list stack

linked list stack

Hi all,
I am trying to solve a problem found on a book slides(Problem solving with C++,Walter Savitch) and i got some problems.

I am supposed to do my own the push function for the stack, so i create a new ptr,
 void Stack::push(char the_symbol)
    {StackFramePtr temp_ptr = new StackFrame;

and then i try to point the link from the head to the new node
and i get this error
Segmentation fault (core dumped)
Apart that I dont know what this error means, even though i search for it on the net, i dont see why this command top->link=temp_ptr; would cause that!

Top is declared on the header file as
StackFramePtr top;

There is this function
//Body intentionally empty

would i have to initialize the top pointer here? The problem is that this function is not called by anyone else on the main program that was predone for me.

I guess i could initialise it if the stack is empty and never again.

Thanks in advance

RE: linked list stack

No worries everybody,
I figured it out. Well actually i didnt, i just typed everything again and it worked! most likely some typo somewhere!

RE: linked list stack

May be it was not a misprint? Have you any logic before


top->link - temp_ptr;
in Stack::push? You have top == 0 when the 1st char pushed into the empty stack, so segmentation fault etc...

Use TGML tag CODE for your snippets, please.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close