Knowee
Questions
Features
Study Tools

Which data structure can be used to implement both stack and queue (only one data structure)

Question

Which data structure can be used to implement both stack and queue (only one data structure)

🧐 Not the exact question you are looking for?Go ask a question

Solution

A linked list can be used to implement both a stack and a queue.

For a stack, you can use the linked list by adding and removing elements from the head of the list. This way, the last element added (the one at the head of the list) will be the first one to be removed, following the LIFO (Last In, First Out) principle of a stack.

For a queue, you can also use the linked list by adding elements at the tail of the list and removing them from the head. This way, the first element added (the one at the head of the list) will be the first one to be removed, following the FIFO (First In, First Out) principle of a queue.

So, a linked list can be used to implement both a stack and a queue, depending on how you add and remove elements.

This problem has been solved

Similar Questions

Which data structure can be used to implement both stack and queue (only one data structure)*2 pointsStackQueueDequeueNone of the above

Which of the following data structures can be used to implement a queue?StackLinked listArrayBoth B and C

Implement Stack using Queues

Which one of the following is an application of Queue Data Structure?

How many stacks are needed to implement a queue? Consider the situation where no other data structure like arrays, linked list is available to you.ans.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.