• Linear (Sequential) Queue

    Linear (Sequential) Queue

    This Linear (Sequential) Queue, is a linear list DATA STRUCTURE used to represent a linear list and permits deletion to be performed at one end of the list and the insertion at the other end. The information in such a list is processed in the same order as it was received, that is on first-come-first-out (FIFO) basis. The Railway Reservation counter is an example of queue where the people collect their tickets on the first-come-first-serve (FIFS) basis. There are two types of operations possible on the linear queue.

    1. Insertion (from rear side)
    2. Deletion (from front side)

    USE OF QUEUE :

    Two common ways in which queues may be implemented are as follows:

    1. Arrays
    2. Pointers

    A queue has two pointers front and rear, pointing to the front and rear elements of the queue, respectively. Consider a queue Q consisting of  n elements and an elements  Value, which we have no insert into the Q. The value NULL (0) of front pointer implies an empty queue and the MAXVALUE implies the queue is full.

    Linear (Sequential) Queue Program Code

    ALGORITHM OF QUEUE:

    1. Insert Operation:

    Insert operation inserting the new value from the rear side (right hand side). The first value is arranged in the queue as a left most value (in queue as first value) and second value is also inserted on rear side and set behind first value. Thus, each new value is set behind the previous entered value.

    Step 1: [Check overflow condition]if rear >= size

    Output “Overflow” and return

    Step 2: [Increment rear pointer]

    Rear = rear + 1

    Step 3: [Insert an element]

    Q [rear] = value

    Step 4: [Set the front pointer]

    If front  = 0

    front = 1

    Step 5: return

    Example – Insert operation of Linear Queue in C Language

    insert(){

    int newitem;

    if(rear>=SIZE)

    {

    printf(“Your QUEUE is FULL…\n”);

    return;

    }

    else

    {

    printf(“Enter New Value :”);

    scanf(“%d”,&newitem);

    arr[++rear]=newitem;

    }

    if(front==0)

    front=1;

    getch();

    return;

    }

    1. Deletion Operation:

    Deletion Operation is used to remove the values in the queue. It is works on the first-in-first-out (FIFO) basis, means, it is removed item from the front side (at the right hand side of the queue). This operation is removed first entered item after second entered item and so on in the queue.

    Step 1: [Check underflow condition]if front = 0

    Output “Underflow” and return

    Step 2: [Remove an element]

    Value = Q [front]

    Step 3: [Check for empty queue]

    If front = rear

    front = 0

    rear = 0

    else

    front = front + 1

    Example – Delete operation of Linear Queue in C Language

    rem(){

    int remitem;

    if(front>rear)

    {

    printf(“Your QUEUE is EMPTY…\n”);

    front=0;

    rear=0;

    return;

    }

    else

    {

    remitem=arr[front++];

    printf(“The Removed Item Is %d.\n”,remitem);

    }

    getch();

    return;

    }

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *