answersLogoWhite

0

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.

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is time complexity of stack?

All major queue operations (push, pop and front) are constant time operations.


Write a c program to perform stack operation?

int top=-1; int stack[10];


What are the different between stack and queue?

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'.


Why does LIFO order follows in stack and why does FIFO order follows in queue?

LIFO and stack are synonyms, so are FIFO and queue.


What is difference between stack snd 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).


What is different between primitive date type and non primitive data type in c plus plus programming language?

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.


Is cursor implementation possible in queue or stack?

yes,cursor implementation possible in priority queue.


Double ended stack?

Double ended queue


Write a program in c language to reverse elements of a 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; }


Basic operation of stack and 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.


How can you implement a queue using stacks efficiently?

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.


What are the stack operation?

there are two operations you can do with a STACK one is PUSH operation and the other is POP operation