answersLogoWhite

0

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.

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

How do you implement stack without array?

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?

Explain The merits of using a deque to implement a stack in data structure


Can you implement merge sort without using recursion?

Sure, recursion can always be substituted with using a stack.


How can implement round robin sceduler in java using circular doubly linked list?

I'm sorry brother


Why stack is implemented by link list?

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.

Related Questions

Is it possible to implement stack and queues using linkes list?

Yes it is possible to implement stack and queue using linked list


How do you implement stack without array?

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?

Explain The merits of using a deque to implement a stack in data structure


What are advantages of stack?

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.


Can you implement merge sort without using recursion?

Sure, recursion can always be substituted with using a stack.


How can you implement a queue using stacks efficiently?

To implement a queue using stacks efficiently, you can use two stacks. One stack is used for enqueueing elements, and the other stack is used for dequeueing elements. When dequeueing, if the dequeue stack is empty, you can transfer elements from the enqueue stack to the dequeue stack to maintain the order of elements. This approach allows for efficient implementation of a queue using stacks.


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


What is the relationship between a stack and an array?

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.


How should you design a scientific calculator using C plus plus?

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.


Where linked list using?

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


How can implement round robin sceduler in java using circular doubly linked list?

I'm sorry brother


Why stack is implemented by link list?

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.