954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

linked stack question.

I've used linked lists before. Does anybody have a resource or url address on how to write a linked stack? I need to create a stack with a menu using int and char variables.

Thanks.

yaan
Newbie Poster
8 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

I've used linked lists before. Does anybody have a resource or url address on how to write a linked stack? I need to create a stack with a menu using int and char variables.

Thanks.

A stack with a 'menu'? What do you mean by 'menu'?

Creating a linked stack is simple, if you've already written a linked list:

Step 1. Write a linked list.
Step 2. Create a function for pushing an element onto the front of the list. Call this 'push'.
Step 3. Create a function for removing the first element of the list. Call this 'pop'.
Step 4 (optional). Create a function that returns the first element of the list by reference, so it can be used as an lvalue. Call this 'top'.

Viola, you have a linked stack! And of course, with 'function', you can interpret that as 'member function' or 'method': whatever suits you.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

what I mean by a menu are choices (1 - push a character/integer, 2 - pop a character/integer, 3 - display all, etc..). I assume I'll be using the switch to accomplish this.

Thanks.

yaan
Newbie Poster
8 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

yeah
the switch statment shud solve all ur probs..
for any source code u want i think the best site is
www.planetsourcecode.com
u ll get everything in tht site..

shre86
Light Poster
33 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You