Articles

Queue

In Materi, Struktrur Data on January 6, 2011 by khalifrinaldi

FIFO queue
queue is a type of container adapter, specifically designed to operate within the context of the FIFO (first-in first-out), where the elements inserted into one end of the container and is extracted from the other.

queue is implemented as an adapter container, which is a class that uses a special class kapsulasi object as the underlying container, providing a set of specific functions of a member to access elements. Element pushed into the “back” of certain container and emerged from the “front” her.
in c + +, the queue can be implemented in two ways. First use the Array and the second is a link list. most temen – temen certainly more frequent use of Array. karna is easier in algoritmanya.tapi Array is limited and can not allocate address as linked lists.

type of queue:
1.queue
2.priority queue
3.circlar queue

The following functions are in the queue classes.
include the following:

1. (Constructor) Construct queue
2.empty
Return 3.size size
4.front
5.last
6.enqueue Insert element
7.dequeue Delete next element

1.) Constructor queue
Building a container object adapter queue.
A container adapter storing objects as data containers. Container object is a copy of the argument passed to the constructor, if any, otherwise this is an empty container.

2 only.) Full
test whether the queue or queue container is full or not. if full, the queue can not be added

3.) Empety function
Test whether container is empty
Returns whether an empty queue, namely whether the measure is 0.

4.) Front ()
each queue there mesty oldest element, or elements at the front (front),
front or front of the array that is the nth element, and most end or the back of the element to an-0
for example we have of an array A [] with the number of elements of n. the element in front or at the front is the element A [n-1]

5.) Enqueue ()
push operation in the queue that is entering the operating element in the queue. or better known by Enqueue;
for example in the linked list:

now = new node;
if (head == NULL)
{
now-> kar = ch;
now-> next = NULL;
tail = now;
head = now;

}
else
{
now-> kar = ch;
now-> next = NULL;
taels-> Next = now;
tail = now;
}

whereas in the array are:

if (full (lot)) court <<“Queue full ‘;
else if (A [0] == ‘0 ‘) {
A [0] = x;
more + +;}
{else
for (int i = much; i> = 0; i-)
A [i +1] = A [i];
A [0] = x;
many ++;}}

6.) Dequeue ()
is the opposite of the Enqueue, dequeue is surgery to remove a character from a queue. issued is the leading or front element.
following surgery in the links list
node * temp;
temp = head;
head = head-> next;
delete temp;

Leave a comment

Design a site like this with WordPress.com
Get started