Hello my friends. I coded a doubly linked list here and i have implemented stacks and queues.....or so i think. Im posting my code to see if I really did implement Stacks and Queues in my code or if im just doing a print and reverse print of my nodes. Sorry if my explanation is off but my code will help you better understand what I mean.
would I need a counter? I have decided to use names instead of numbers is that ok???? im really doubting myself for some reason....well thanks for looking at my post and for the help, in advance.
if im just doing a print and reverse print of my nodes
Yes you did.
A Stack is a LIFO container.
By definition , you can push to it,consequently adding an element to the top of it. pop from it , consequently removing the top element and retrieve it
(optional)peek the top element.
Reference : http://en.wikipedia.org/wiki/Stack_(abstract_data_type)
A Queue is a FIFO (optionally ordered) container.
By definition , you can enqueue an element at its back, dequeue an element from its front , consequently removing it and retrieve it.
(optional)peek at the front element.
Reference:http://en.wikipedia.org/wiki/Queue_(data_structure)
So you need to add those respective functions,like
thanks i appreciate the help. when i said counter i meant an accumulator but i dont need one. yea im still trying to teach myself about queue and stacks but to implement them gets a little confusing for me as you can see in my code. Although i find it a little bit easier to code it in c++ than c#.
man im really not getting it.....looking your example is that i have to create another struct then i would have to create a void function and from the void, pass the stack by reference to my main and then call the function "void push_stack" from my main?
Look at my previous post,a stack(see std::stack) and a queue(see std::queue) are containers ,look at the respective Wikipedia articles.
They should have the given functions , that said i gave you an example of how it could be implemented using your doubly-linked list's node.While there could be other functions like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void push_stack(mystack& st,string data);//c-style independent data structures and functions
string pop_stack(mystack& st);
int size_stack(mystack& st);
//other useful functions
//...
//or using classes/structs
template<class data_type>
struct stack
{
private:
//a stack is just wrapper,
//underlying implementation could be linked list etc.
public:
data_type pop();
void push(data_type data);
size_t size();
//other useful functions...
}