What Is Queue In Data Structure | What Is Queue | Queue Operations | Queue Data Structure In C | Queue Using Linked List | Priority Queue In Data Structure

What Is Queue In Data Structure | What Is Queue | Queue Operations | Queue Data Structure In C | Queue Using Linked List | Priority Queue In Data Structure

What Is Queue In Data Structure | What Is Queue | Queue Operations | Queue Data Structure In C | Queue Using Linked List | Priority Queue In Data Structure

Queues in data structure

Line is a dynamic information structure, to some degree like Stacks. Not at all like stacks, a line is open at the two its finishes. One end is constantly used to embed information (enqueue) and the other is utilized to expel information (dequeue). Line takes after First-In-First-Out philosophy, i.e., the information thing put away first will be gotten to first.



Line Example

A genuine case of line can be a solitary path one-way street, where the vehicle enters to start with, exits first. All the more true cases can be viewed as lines at the ticket windows and transport stops.

Queue Representation

As we now comprehend that in line, we get to the two closures for various reasons. The accompanying graph given underneath tries to clarify line portrayal as information structure −




Line Example

As in stacks, a line can likewise be actualized utilizing Arrays, Linked-records, Pointers and Structures. For straightforwardness, we might actualize lines utilizing one-dimensional exhibit.

Essential Operations

Line operations may include introducing or characterizing the line, using it, and after that totally deleting it from the memory. Here we should attempt to comprehend the essential operations related with lines −



enqueue() − include (store) a thing to the line.

dequeue() − expel (get to) a thing from the line.

Hardly any more capacities are required to make the previously mentioned line operation productive. These are −

look() − Gets the component at the front of the line without expelling it.

isfull() − Checks if the line is full.

isempty() − Checks if the line is void.

In line, we generally dequeue (or access) information, pointed by front pointer and keeping in mind that enqueing (or putting away) information in the line we take help of back pointer.

We should first find out about strong elements of a line −

look()

This capacity sees the information at the front of the line. The calculation of look() work is as per the following −

Calculation

start methodology look

return queue[front]

end technique

Execution of look() work in C programming dialect −

Case

int look() {

return queue[front];

}

isfull()

As we are utilizing single measurement cluster to execute line, we simply check for the back pointer to reach at MAXSIZE to discover that the line is full. On the off chance that we keep up the line in a round connected rundown, the calculation will vary. Calculation of isfull() work −

Calculation

start technique isfull

in the event that back equivalents to MAXSIZE

return genuine

else

return false

endif

end technique

Execution of isfull() work in C programming dialect −

Illustration

bool isfull() {

if(rear == MAXSIZE – 1)

return genuine;

else

return false;

}

isempty()

Calculation of isempty() work −

Calculation

start strategy isempty

on the off chance that front is not as much as MIN OR front is more noteworthy than raise

return genuine

else

return false

endif

end technique

In the event that the estimation of front is not as much as MIN or 0, it tells that the line is not yet instated, subsequently vacant.

Here’s the C programming code −

Case

bool isempty() {

if(front < 0 || front > raise)

return genuine;

else

return false;

}

Enqueue Operation

Lines keep up two information pointers, front and back. Accordingly, its operations are relatively hard to actualize than that of stacks.

The accompanying strides ought to be taken to enqueue (embed) information into a line −

Step 1 − Check if the line is full.

Step 2 − If the line is full, deliver flood mistake and exit.

Step 3 − If the line is not full, increase raise pointer to point the following unfilled space.

Step 4 − Add information component to the line area, where the back is pointing.

Step 5 − return achievement.

Embed Operation

Once in a while, we additionally verify whether a line is instated or not, to deal with any unexpected circumstances.

Calculation for enqueue operation

methodology enqueue(data)

on the off chance that line is full

return flood

endif

raise ← raise + 1

queue[rear] ← information

return genuine

end technique

Execution of enqueue() in C programming dialect −

Case

int enqueue(int information)

if(isfull())

return 0;

raise = raise + 1;

queue[rear] = information;

return 1;

end system

Dequeue Operation

Getting to information from the line is a procedure of two errands − get to the information where front is pointing and expel the information after access. The accompanying strides are taken to perform dequeue operation −

Step 1 − Check if the line is unfilled.

Step 2 − If the line is unfilled, deliver undercurrent mistake and exit.

Step 3 − If the line is not vacant, get to the information where front is pointing.

Step 4 − Increment front pointer to point to the following accessible information component.

Step 5 − Return achievement.

Expel Operation

Calculation for dequeue operation

technique dequeue

in the event that line is vacant

return sub-current

end if

information = queue[front]

front ← front + 1

return genuine

end technique

Execution of dequeue() in C programming dialect −

Case

int dequeue() {

if(isempty())

return 0;

int information = queue[front];

front = front + 1;

return information;

}

 

Thanks for reading this post and don’t forget to share it and keep visits for more updates



About Ashok.cse

Hi, I'm currently studying for the Bachelor of Technology In Computer Science from Rajasthan Technical University. I am the web developer with 3+ years of experience. my range of developer services including creating the design for new apps and web platforms or building UI design for mobile, tablets or desktops. making UX designs wireframes and layouts concepts and redesigns websites are adapting to mobile and responsive design. I have worked with many clients. I am working professionally with WordPress And Adobe tools.

View all posts by Ashok.cse →

Leave a Reply

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