Reputation: 11
So I guess my question is a bit noobish but we've just started linked lists, stacks and queues and I'm feeling a bit lost in terms of syntax.
I have a working linked list structure with adding to back and front, pushing, popping, deleting etc.. but I get crazy lost when it comes to calling those functions in the stack implementation. The Linked List class declaration is in a header file with function definitions in a .cpp file. The stack is exactly the same story. We have been given the header file with function declarations and we need to write our own definitions in a separate .cpp file.
My problem lies in calling the linked list functions in the stack functions. The stack includes an "LList data" (the linked list structure is called LList); a pointer to an integer (I'm assuming) "int *data" and and integer tracking the top of the stack "int t"
The funcitons we have to write are the constructor, destructor, pop, push and size functions. I'd give source code but it really isn't anything significant to work with at all.
I hope my question can be understood >_< Thanks in advance Cameron
Upvotes: 0
Views: 697
Reputation: 1198
A stack is just a linked list with different interface functions. You only need to be able to push
elements to the "top" of the stack, and pop
from the top.
It looks like your Stack
class implementation is designed to be a wrapper around the LList
class you already have.
Without going into the details (which is kinda hard without looking at the code),
Stack
class with a LList
as a member variable (preferably private).push
function should simply insert to the tail of your linked list.pop
function should remove the last element from the tail of your linked list~Stack
implementation should delete the LList
object you created; you can skip this if you use smart pointers, or use the delete
keyword if you manually created an object using new
.More code will help refine this answer.
Upvotes: 1