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
Definition of Algorithm Algorithm must have the following five characteristic features: 1.      Input 2.      Output 3.      Definiteness 4.      Effectiveness 5

write an algorithm for multiplication of two sparse matrices using Linked Lists

nested for loop for (i = 0; i for (j = 0; j sequence of statements } } Here, we observe that, the outer loop executes n times. Every time the outer loop execute


Handout 15 COMP 264: Introduction to Computer Systems (Section 001) Spring 2013 R. I. Greenberg Computer Science Department Loyola University Water TowerCampus, Lewis Towers 524 82

Question 1 . Give the structure of PL/SQL Blocks and explain Question 2 . Differentiate between PL/SQL functions and procedures Question 3 . Explain the following Par

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

Stacks are often used in evaluation of arithmetic expressions. An arithmetic expression contains operands & operators. Polish notations are evaluated through stacks. Conversions of

Type of Qualitative Method: Different  qualitative methods are suitable for different  types of study. Quite often we can  combine  qualitative and quantitative  methods. Many

In a sorted list, Binary search is carried out by dividing the list into two parts depends on the comparison of the key. Since the search interval halves each time, the iteration o