answersLogoWhite

0


Best Answer

Suppose we have a Queue as follows: E -> D -> C -> B

We maintain a head pointer to E and a tail pointer to B.

To add an element, we make a new queue item (say A), we set B->next = A, and set tail = A.

To delete an element, we let a temp pointer to the head (say tempHead = head), set head = E->next and deallocate tempHead.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Implement a queue using a singly linked list l the operations insert and delete should still take o1time?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you implement stack using linked list in turbo c?

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.


What operation is supported in constant time by the doubly linked list but not by the singly linked list?

examples:- delete this node (identified by a pointer)- insert a new node before this node- replace this node with another node


What pointer type will you use to implement a heterogeneous linked list in c?

void pointer


Explain the features of doubly linked list?

Well, in a singly linked list you can only move forward, if the pointer you seek is behind your current position you'll have to cross the hole list to get there. In a doubly linked list you can simply move back as well as forward.... hope this helps...


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.

Related questions

How do you implement stack using linked list in turbo c?

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.


What operation is supported in constant time by the doubly linked list but not by the singly linked list?

examples:- delete this node (identified by a pointer)- insert a new node before this node- replace this node with another node


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

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


Which is the easy insertion operator single linked-list or double-linked list?

It is easier to insert into a singly linked list.


what are the various operations in linked list which can be performed on linked list?

Some common operations that can be performed on a linked list include inserting a node, deleting a node, searching for a specific node, traversing the list, and updating a node's value. Other operations may include reversing the list, merging two lists, sorting the list, and finding the length of the list.


Can you insert node in the middle of linked list?

Yes, it is easy.


What pointer type will you use to implement a heterogeneous linked list in c?

void pointer


What is macro operations?

Macro operations are those not linked to individual types and invoked on objetcs - but rather general operations associated with the database as a whole.


Explain the features of doubly linked list?

Well, in a singly linked list you can only move forward, if the pointer you seek is behind your current position you'll have to cross the hole list to get there. In a doubly linked list you can simply move back as well as forward.... hope this helps...


Adavantage of pointer based of a list over an array?

One advantage of a linked list (with pointers) is that it is fairly cheap to insert or delete an element - once you know where it is. A disadvantage is that getting a specific element - for example, the 1000th. element - is expensive.


Why you use doubly link list?

In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.


Convert single linked list to double linked list?

You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.