Discover the depth  of  C

  C C++  Linux ProgrammingNEW   Operating Systems  Data StructuresNEW  Compilers  Contact Us

Navigation

Join C4SwimmersGroup

 sitepromotion.gif (577 bytes) New Member

Data Structures

  Introduction

Stacks

  About Stacks

  Types of Notations

  Infix to Postfix

  Infix to Prefix

  Evaluating Postfix

Queues

  About Queues
  Circular Queue
  Priority Queue
Linked Lists 
 About Linked Lists
 Singly Lists
 Doubly Lists
 Circular Lists
 Circular Doubly Lists
Sorting
 Bubble Sort
 Insertion Sort
 Selection Sort
 Shell Sort
 Merge Sort
 Quick Sort
Searching
 About Searching
 Linear Search
 Binary Search
Online Certifications
premiumservices.gif (1070 bytes) Brainbench
premiumservices.gif (1070 bytes) Benchmarks Global
Help and Support
customer_care_small.gif (1018 bytes) Suggestions
post-question_icon.gif (1062 bytes) Contribute
premiumservices.gif (1070 bytes) Feedback
premiumservices.gif (1070 bytes) Advertise with us
 

 memberhome.gif (1052 bytes) -Home Page-

 
 
.  

C For Swimmers : Mastering C step-by-step

Google


WWW c4swimmers.esmartguy.com

About Queues

 

Definition : 

Lists permit deletions to be performed at one end of a list and insertions at the other end. The information in such a list is processed in the same order as it was received, i.e. on a first-in, first-out (FIFO) or first-come first-serve (FCFS) basis. This type of list is referred to as a Queue.

 

QUEUE STRUCTURE

D = { d , F , A }

Where,

d : Array or a node (structure)
d = { a , FRONT, REAR }
Here, a : Simple array or structure

FRONT : Pointer to the front element of a queue

REAR : Pointer to the rear element of a queue

F : QINSERT, QDELETE, Q DISPLAY, QMODIFY

A : QFULL, QEMPTY

 

Types of Queues

  • Linear Queue
  • Circular Queue
  • Prioirity Queue

 

The insertion operation is referred to as QINSERT and the deletion operation as QDELETE. We can insert an item at the rear end using QINSERT and remove an item at the front end using QDELETE as shown in the fig(a).

 

A pointer FRONT and REAR

FRONT and REAR, pointers to the front and rear elements of queue respectively. Each time a new element is inserted in the queue, the REAR pointer is incremented by 1. The FRONT pointer is incremented by 1 each time a deletion is made from the queue. FRONT and REAR pointers should be reset to -1 once they are found equal.


ALGORITHM : LINEAR QUEUE

Procedure QINSERT(Q,F,MAX,X) : Given F and R, pointers to the front and rear elements of a queue. A QUEUE Q consisting of MAX elements and an element X. this procedure inserts X at the rear end of the queue prior to the first invocation of the procedure, F and R have been set to -1.

STEP 1: [Is front pointer properly set]
if (F==R)
then F <-- R <--  -1

STEP 2: [Check for overflow condition]
if (R>=(MAX-1))
then write ('Error : Overflow')
Return

STEP 3: [Increment rear pointer]
R <-- R+1

STEP 4: [Insert element]
Q[R] <-- X
Return



Procedure QDELETE(Q,F,R) : Given F and R,the pointers to the front and rear elements of a queue respectively and the queue Q to which they correspond. This procedure delets and returns the element at the front end of the queue .Here X is a temporary variable.

STEP 1: [Check for underflow condition]
if (F>=R)
then write('Error : Underflow']
Return

STEP 2: [Increment the front pointer]
F <-- F+1

STEP 3: [Delete element]
Y <-- Q[F]
Return Y


premiumservices.gif (1070 bytes) Click Here: Linear Queue source code written in C.


You are Visitor No.

Sign my Guestbook View my Guestbook

Subscribe to C4Swimmers Group
Designed and Maintained by  Nanda Kishor

Thanks for using C For Swimmers.
Regarding this material, you can send Bug Reports, Suggestions, Comments, etc. to

nandakishorkn@rediffmail.com

Note: All logos or trademarks are related to their respective owners.

Although every precaution has been taken, the designer(s) owe no responsibility for malicious errors.

No liability assumed for damages resulting from the use of the available information.