Primitive Operations
:
enqueue(o)
Put object o on the end of the queue.
dequeue()
Remove and return the object at the front
of the queue.
head()
Reveal the front object in the queue, but
do not remove it.
size()
Return the number of objects currently in
the queue.
capacity()
Return the maximum number of objects
the queue can hold.
Other operations can be defined in terms of these primitive on
es. For
example:
•
isEmpty()
can be defined by testing whether size() is 0.
•
isFull()
can be defined by testing whether size() equals the capac-
ity().
These last two could also be considered primitive operation
s. There is
a balance between minimizing the set of primitive operation
s, versus
providing many convenient operations for users.
All major queue operations (push, pop and front) are constant time operations.
A stack is generally First In, Last Out, and a queue is First In First Out.Item can be added or removed only at one end in stack and in a queue insertion at the rear and deletion from the front.The basic operation of stack are 'push' and 'pop', on other hand of queue are 'enque' and 'dequeue'.
LIFO and stack are synonyms, so are FIFO and queue.
A primitive data type is built into the language - int, char, long, etc. A non-primitive data type is am abstract data type that is built out of primitive data types - linked list, queue, stack, etc.
yes,cursor implementation possible in priority queue.
All major queue operations (push, pop and front) are constant time operations.
int top=-1; int stack[10];
A stack is generally First In, Last Out, and a queue is First In First Out.Item can be added or removed only at one end in stack and in a queue insertion at the rear and deletion from the front.The basic operation of stack are 'push' and 'pop', on other hand of queue are 'enque' and 'dequeue'.
LIFO and stack are synonyms, so are FIFO and queue.
In stack , the object which is last in will be first out (LIFO), whereas in queue the object which is first in will be first out (FIFO).
A primitive data type is built into the language - int, char, long, etc. A non-primitive data type is am abstract data type that is built out of primitive data types - linked list, queue, stack, etc.
yes,cursor implementation possible in priority queue.
Double ended queue
There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue<Item> reverse (Queue<Item> queue) { Stack<Item> stack; Item item; while (queue.remove(&item)) { stack.push(item); } while(stack.pop(&item)) { queue.add(item); } return queue; }
A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.
To implement a queue using stacks efficiently, you can use two stacks. One stack is used for enqueueing elements, and the other stack is used for dequeueing elements. When dequeueing, if the dequeue stack is empty, you can transfer elements from the enqueue stack to the dequeue stack to maintain the order of elements. This approach allows for efficient implementation of a queue using stacks.
there are two operations you can do with a STACK one is PUSH operation and the other is POP operation