answersLogoWhite

0


Best Answer

If you already have a linked list implementation, you can use it as a queue by making a few changes:

* Add a queue() function to add a node to the end of the list * Add a dequeue() function to remove and return the first node

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

You wouldn't use an array to implement either a stack or a queue. By their nature, queues and stacks are variable length, thus are better suited to linked lists which can dynamically expand and contract.

In both cases, a singly-linked list suffices, where each element points to the next element and the last element points to NULL.

A stack is a last in, first out structure (LIFO structure), where all insertions and extractions occur at the head of the list. Therefore you only need to maintain a pointer to the head of the list.

A queue is a first in, first out structure (FIFO structure), where all insertions occur at the tail while all extractions occur at the head. Therefore you need to maintain two pointers, one at the head and one at the tail.

The head and tail pointers are required to permit constant time access to the head and tail of the list.

Priority queues are a variation on the standard queue, such that elements are prioritised. This is achieved by giving each element a weighted value and sorting by that value. Lower values have higher priority than larger values, thus you must traverse the list until you locate an element with a greater weight than the new element, and insert the new element in front of the greater element. Insertions of this type are not constant time (they are linear time), however if the number of weights is finite, the number of insertion points are also finite, therefore separate pointers can be maintained in an array thus permitting constant time access to each insertion point.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you use the link lists as queue?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the use of queue?

The queue is the the concept involved in Algorithms where you use stack, queue and lists to store the different data items e.g people waiting for the bus at bus stop the first in queue will enter first this is called FIFO (first in first out).......


How do you use queue in a sentence?

the barber's favorite braid is the queue


What is the use of insertion queue in 8086?

Maybe you mean the prefetch queue?


How do you use queue to write a sentencs?

Example 1: I am standing in the ATM queue Example 2: Please be in queue


What is upink frequecy in GSM?

It varies - according to which system is in use. The related link to Wikipedia lists the uplink & downlink frequencies.


What is the advantage of circular queue over simple queue?

Circular queue have less memory consuption as compared to linear queue because while doing insertion after deletion operation it allocate an extra space the first remaining vacant but in circular queue the first is used as it comes immediate after the last.


What is the best link lists provider for GSA Search Engine Ranker?

I'm using SErocket link lists and can highly recommend them - serocket.net/linklist/


What are types of Queue?

Queue is a data structure which is based on FIFO that is first in first out. Following are the types of queue: Linear queue Circular queue Priority queue Double ended queue ( or deque )


How do you unqueue pvp and arenas?

To unqueue from the (random) battleground and arena queue, simply hit the "H" key, which will take you to the PvP screen. On the second tab, there should be a button at the bottom reading "Leave Queue". Pressing this will remove you from the queue. It is the same button (now: Enter Queue) which you use to enter the queue in the first place.


How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


Do you use a semicolon when separating lists?

No, semicolons are not typically used to separate items in a list. Commas are commonly used for that purpose. Semicolons are used to separate independent clauses in a sentence or to separate items in a list where the items themselves contain commas.


Which queue most efficient queue using array?

circular queue