Link to home
Start Free TrialLog in
Avatar of krn
krn

asked on

linked list rep. of stack

What is the code for a linked list rep. of a stack in C++.
Lost my code. need it though.
Avatar of alexo
alexo
Flag of Antarctica image

This question sounds suspiciously like homework.  In that case t will be unethical for us to write it for you.  However, we can help with *specific* problems.

To get you started:

A stack usually implements two operations, PUSH - which pushes an item on the stack and POP - which returns the topmost item and removes it from the stack (sometimes the query and removal are split into two distinct operations).

An implementation using a linked-list can either add and remove items from the beginning of the list (if the list supports such operations) or keep a pointer to the last item.

Case #1:
  PUSH(item) - Add the new item to the beginning of the list.
  POP() - Return the first item and remove it from the list.

Case #2:
  PUSH(item) - Add the new item to the end of the list and update the pointer.
  POP() - Return the item pointed to (last item) and remove it from the list.

Avatar of krn
krn

ASKER

Well in that case, I must decrease the points.
I will, on the pother hand, ask more questions about the problem as they arise.
ASKER CERTIFIED SOLUTION
Avatar of baprebap
baprebap

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of krn

ASKER

Thanks
That is really what I was having problems with.
>> Well in that case, I must decrease the points.
You cannot decrease points for a question.  However, you can delete a question that has no pending or rejected answers and submit another one (that is the reason I gave a comment and not an "answer").

This is just for reference since I see you got your answer.