Wednesday, 18 May 2016

Queue IN Data Structuretccicomputercoaching.Com



Queue IN Data Structuretccicomputercoaching.Com
Data structure: It’s a way in computer science to organize data properly in such a way that we can use data efficiently.
What is Queue?
Queue is also an abstract data type or a linear data structure, in which the first element is inserted from one end called REAR (also called tail), and the deletion of existing element takes place from the other end called as FRONT (also called head). This makes queue as FIFO data structure, which means that element inserted first will also be removed first.
Like Stack, Queue is also an ordered list of elements of similar data types.
A queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in orderand the principal (or only) operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed.
Real Example of Queue:
A queue at window of movie-ticket. The person who is standing first, its turn comes first, he/her comes first out.
Queue can be implemented using an Array, Stack or Linked List. The easiest way of implementing a queue is by using an Array. A bounded queue is a queue limited to a fixed number of items.
One characteristic of a queue is that it does not have a specific capacity. Regardless of how many elements are already contained, a new element can always be added. It can also be empty, at which point removing an element will be impossible until a new element has been added again.
Fixed length arrays are limited in capacity, but it is not true that items need to be copied towards the head of the queue.
Operations –
1. createQueue Operation– This operation takes the maximum number of elements
(maxElements) the Queue can hold as an argument, creates a Queue according to it and returns a pointer to the Queue. 
2. Enqueue Operation - This Operation takes the pointer to the top of the queue Q and the item (element) to be inserted as arguments. Check for the emptiness of queue.
3. Dequeue Operation - This Operation takes the pointer to the top of the stack S as an argument and will then dequeue an element.
4. Front function – This function takes the pointer to the top of the queue Q as an argument and returns the front element of the queue Q.  
Queue overflow results from trying to add an element onto a full queue and Queue underflow happens when trying to remove an element from an empty queue.
If you like this post then please share and like the post.
Visit us @ tccicomputercoaching.com
Call us @ 98256 18292

No comments:

Post a Comment