Assume the Linked list has following operations
1.node* insert(node* node, bool head); /* head = true if insertion at head else insertion at tail */
2. node* remove(bool head); /* head = true if removal at head else removal at tail */
Now implement the stack functions as below.
STK_RET push(node* pnode)
{
node* head;
head = insert(pnode, true); /* insert the node at head */
if (head)
return STK_OK;
else
return STK_NOK;
}
similarly pop can be implemented to remove the node at head
Also the conventioin of inserting and removal from the tail can be used.
Stacks are often implemented using the same node structure as a linked list.
Explain The merits of using a deque to implement a stack in data structure
Sure, recursion can always be substituted with using a stack.
I'm sorry brother
A Linked-List is basically a series of Nodes. Each Node contains two things: The contents, and the pointer to the next Node in the Linked-List. So you can traverse the Linked-List by following the "next" pointers in each Node, a bit like following road directions from city to city. A stack is an abstract data type where you have two operations: "push" and "pop". Pushing means to put an item in the stack, Popping means to get the first element of the stack. When you push an item onto a stack, you put the item at the top: so its like cutting in line to the very front. The last one in is now first, and thus, the first one out. Another helpful image is a "stack" of trays at a cafeteria -- you can only get the tray from the top of the stack, or put a tray on top of the stack. The very first tray in the stack is actually the one at the very bottom, and thus, the last one to be used. "First in, Last Out." A stack deals with what comes first/last, while a Linked-List describes how data is stored. A stack needs to store data, so a stack can be implemented as a Linked-List.
Yes it is possible to implement stack and queue using linked list
Stacks are often implemented using the same node structure as a linked list.
Explain The merits of using a deque to implement a stack in data structure
some disadvantages created in stack using array then that problem solve to linked list use in stack.First advantage for size of stack not limited in linked list using.second essay to stack programme implement using only one pointer.
Sure, recursion can always be substituted with using a stack.
stack abstract datatype
There is no inherent relationship between the two. It's possible to implement a stack using an array to store date, but that's about it.
The easiest way to implement a calculator is an RPN calculator (enter the numbers first, perform the operation last). You need a last-in-first-out stack (there's a "stack" class in C++, but you can also implement your own using an array or a linked list), and a set of functions that pop the last elements from the stack and push the result (e.g. Add() pops the last 2 values and pushes their addition).You'll need the math.h library for scientific operations.
linked list are used for creation of stack,queues to use memory in optimum manner linked list are used as they are dynamic in nature
I'm sorry brother
A Linked-List is basically a series of Nodes. Each Node contains two things: The contents, and the pointer to the next Node in the Linked-List. So you can traverse the Linked-List by following the "next" pointers in each Node, a bit like following road directions from city to city. A stack is an abstract data type where you have two operations: "push" and "pop". Pushing means to put an item in the stack, Popping means to get the first element of the stack. When you push an item onto a stack, you put the item at the top: so its like cutting in line to the very front. The last one in is now first, and thus, the first one out. Another helpful image is a "stack" of trays at a cafeteria -- you can only get the tray from the top of the stack, or put a tray on top of the stack. The very first tray in the stack is actually the one at the very bottom, and thus, the last one to be used. "First in, Last Out." A stack deals with what comes first/last, while a Linked-List describes how data is stored. A stack needs to store data, so a stack can be implemented as a Linked-List.
Stack is an abstract data type that allows you to input and output data in a way that the first data which was placed in the stack will be the last one to get out. We use physical examples of stack in our daily lives such as the stack of dishes or stack of coins where you only add or remove objects from the top of the stack. You can see the implementation in c++ in related links, below.