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

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);

}

Posted Date: 7/10/2012 3:53:23 AM | Location : United States







Related Discussions:- Implementation of queue by using a single linked list, Assignment Help, Ask Question on Implementation of queue by using a single linked list, Get Answer, Expert's Help, Implementation of queue by using a single linked list Discussions

Write discussion on Implementation of queue by using a single linked list
Your posts are moderated
Related Questions
algorithm to search a node in linked list

The Euclidean algorithm is an algorithm to decide the greatest common divisor of two positive integers. The greatest common divisor of N and M, in short GCD(M,N), is the largest in

What do you mean by hashing? Hashing gives the direct access of record from the file no matter where the record is in the file. This is possible with the help of a hashing func


Ruby implements Range of T Abstract data type Ruby implements Range of T ADT in its Range class. Elements of carrier set are represented in Range instances by recording interna

Construct G for α, n, and W given as command line parameters. Throw away edges that have an asymmetric relation between nodes. That is, if A is connected to B, but B is not connect

Column Major Representation In memory the second method of representing two-dimensional array is the column major representation. Under this illustration, the first column of

include include include /* Definition of structure node */ typedef struct node { int data; struct node *next; } ; /* Definition of push function */

The following DNA sequences are extracted from promoter region of genes which are co-regulated by the same transcription factor (TF). The nucleotide segments capitalized in the giv

The number of leaf nodes in a complete binary tree of depth d is    2 d