Implementation of queue by using a single linked list, Data Structure & Algorithms

Assignment Help:

Q. Perform implementation of a queue using a singly linked list L. The operations INSER and DELETE should take O (1) time.                                                                           

Ans:

Implementation of queue by using a singly linked list:

When implement a queue as a single liked list, a queue q consists of a list and two pointers, q.front and the q.rear.

inserting an element is stated below:

insert(q,x)

{

p=getnode(); info(p) = x; next(p) = null; if(q.rear == null)

q.front = p;

else

next(q.rear) = p;

q.rear = p;

}

deletion is stated below:

remove(q)

{

if(empty(q))

{

printf("queue overflow");

exit(1);

}

p=q.front; x=info(p); q.front=next(p); if(q.front == null) q.rear = null; freenode(p); return(x);

}


Related Discussions:- Implementation of queue by using a single linked list

How to construct binary tree, Q. A Binary tree comprises 9 nodes. The preor...

Q. A Binary tree comprises 9 nodes. The preorder and inorder traversals of the tree yield the given sequence of nodes: Inorder :          E     A    C    K    F     H    D

Unification algorithm, i want to write code for unification algorithm with ...

i want to write code for unification algorithm with for pattern matching between two expression with out representing an expression as alist

Explain circular queues, Circular Queues:- A more efficient queue repre...

Circular Queues:- A more efficient queue representation is get by regarding the array Q(1:n) as circular. It becomes more convenient to declare the array as Q(O: n-1), when  re

Threaded Binary Tree, If a node in a binary tree is not containing left or ...

If a node in a binary tree is not containing left or right child or it is a leaf node then that absence of child node can be represented by the null pointers. The space engaged by

Tower of hanoi problem., Write an algorithm for getting solution to the Tow...

Write an algorithm for getting solution to the Tower's of Hanoi problem. Explain the working of your algorithm (with 4 disks) with appropriate diagrams. Ans: void Hanoi(int

Brute force, Determine the number of character comparisons made by the brut...

Determine the number of character comparisons made by the brute-force algorithm in searching for the pattern GANDHI in the text

Grounded header link list and a circular header link list, What is the diff...

What is the difference between a grounded header link list and a circular header link list? A header linked list is a linked list which always having a special node, known as t

State warnock algorithm, Warnock's Algorithm An interesting approach to...

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

Explain the array and linked list implementation of stack, Question 1. ...

Question 1. How can you find out the end of a String? Write an algorithm to find out the substring of a string. 2. Explain the insertion and deletion operation of linked lis

Circular linked list, In a circular linked list There is no beginning a...

In a circular linked list There is no beginning and no end.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd