Implementation of queue, Data Structure & Algorithms

Assignment Help:

For a queue a physical analogy is a line at booking counter. At booking counter, customers go to the rear (end) of the line & customers are attended to several services from the front of the line. Unlike stack, customers are inserted at the rear end & deleted from the front end into a queue (FIFO).

In computer science, an instance of the queue is print jobs scheduled for printers. These jobs are maintained into a queue. The job fired for the printer first gets printed first. Similar is the scenario for job scheduling in the CPU of computer.

Like a stack, usually a queue also holds data elements of the similar type. Usually We graphically display a queue horizontally. Figure demonstrates a queue of 5 characters.

2141_IMPLEMENTATION OF QUEUE.png

        Figure: A queue of characters

In a queue the rule followed is that elements are inserted at the rear & come off of the front of the queue. After the insertion of an element to the above queue, the position of rear pointer alters as illustrated below. Now the rear is pointing to the new element 'g' added at the rear of the queue.

1597_IMPLEMENTATION OF QUEUE1.png

Figure: Queue of above figure after addition of new element

After the elimination of element 'a' from the front, the queue alters to the following along with the front pointer pointing to 'b'.

705_IMPLEMENTATION OF QUEUE2.png

Figure: Queue of figure 5.2 after deletion of an element

Algorithm for insertion of an element to the queue

Step 1: Create a new element to be inserted

Step 2: If the queue is empty, then go to

Step 3, else perform step 4

Step 3: Make the front & rear point this element

Step 4: Insert the element at the end of the queue and shift the rear pointer to the lately added element.

Algorithm for deletion of any element from the queue

Step 1: verify for Queue empty condition. If queue is empty, then go to step 2, else go to step 3

Step 2: Message "Queue Empty"

Step 3: Delete the element through the front of the queue. If in the queue it is the last element, then carry out step a else step b

a) make front & rear point to null

b) Shift the front pointer further on to point to the next element in the queue


Related Discussions:- Implementation of queue

Flowchart, conversion of centrigral to frahenhit

conversion of centrigral to frahenhit

Simplifying assumptions of wire frame representation, Simplifying Assumptio...

Simplifying Assumptions of wire frame representation Neglect colour - consider Intensity: For now we shall forget about colour and restrict our discussion just to the intensi

Array implementation of a circular queue, A circular queue can be implement...

A circular queue can be implemented through arrays or linked lists. Program 6 gives the array implementation of any circular queue. Program 6: Array implementation of any Circu

Pseudocode algorithm to print the numbers from 1 to 10, 1. Write a pseudoco...

1. Write a pseudocode algorithm to print the numbers from 1 to 10, and then from 10 to 1, using exactly one loop. 2. The function contains() takes a food as an argument and tell

What is class invariants assertion, What is Class invariants assertion ...

What is Class invariants assertion A class invariant is an assertion which should be true of any class instance before and after calls of its exported operations. Generally

Program segment for insertion of an element into the queue, Program: Progra...

Program: Program segment for insertion of an element into the queue add(int value) { struct queue *new; new = (struct queue*)malloc(sizeof(queue)); new->value = val

Determine the critical path and the expected completion, The information in...

The information in the table below is available for a large fund-raising project. a. Determine the critical path and the expected completion time of the project. b. Plot the total

Queue, algorithm for insertion in a queue using pointers

algorithm for insertion in a queue using pointers

State the complex reallocation procedure, State the complex reallocation pr...

State the complex reallocation procedure Some languages provide arrays whose sizes are established at run-time and can change during execution. These dynamic arrays have an in

Several operations on a aa-tree, The following are several operations on a ...

The following are several operations on a AA-tree: 1. Searching: Searching is done using an algorithm which is similar to the search algorithm of a binary search tree. 2. Ins

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