Advertisements
Advertisements
Question
Differentiate between a stack and a queue.
Advertisements
Solution
| Stack | Queue | |
| 1. | The stack is based on the LIFO (Last In First Out) principle. | The queue operates on the FIFO (First In, First Out) principle. |
| 2. | Insertion Operation is called Push Operation. | The insertion operation is known as the Enqueue Operation. |
| 3. | Deletion Operation is termed Pop Operation. | The deletion operation is known as the dequeue operation. |
| 4. | Push and Pop operation occurs from one end of the stack. | Enqueue and dequeue. Operation occurs from a separate end of the line. |
| 5. | The most accessible element is termed the Top, while the least accessible element is called the Bottom of the stack. | The insertion end is termed the Rear End, while the deletion end is called the Front End. |
| 6. | Simple implementation | Compared to the stack, the implementation is more complex. |
| 7. | Only one pointer is used to perform operations. | Two pointers are used to perform operations. |
| 8. | Empty condition is checked using Top=-1 |
Empty condition is checked using Front=-1 | | Front=Rear+1. |
| 9. | Full condition is checked using Top=Max-1. |
Full condition is checked using Rear=Max-1. |
| 10. | There are no variants available for stack. | There are three sorts of variants, including circular queue, double-ended queue, and priority queue. |
| 11. | It can be regarded as a vertical collection of visuals. | Can be regarded a horizontal collection graphic. |
| 12. | Used to overcome recursive-type difficulties. | Used to tackle problems with sequential processing. |
APPEARS IN
RELATED QUESTIONS
---data structure does not require contiguous memory allocation
(i) Array
(ii) String
(iii) Pointer Array
(iv) Linked List
Define:
(i) Tree
(ii) Binary Tree
(iii) Extended Binary
Write an algorithm for the binary search method. Explain algorithm with a suitable example.
What is a Record ? How it is represented in Memory ?
Explain with flowchart the following control structure : Sequence Logic
write difference between Linear Search and Binary Search.
Define the following term with reference to Tree:
Root
Define the following term with reference to Tree:
Leaf
What is Array?
Write an algorithm for Traversing Linear Array.
Define Array and Pointer Array in the data structure.
Explain Linear data Structure and Non-linear Data Structure.
Define Entity.
Explain Binary Scarch algorithm with a suitable example.
Explain memory representation of linked list with example.
The keyword used by a class to acquire the properties of an interface is:
A double ended queue is a linear data structure which enables the user to add and remove integers from either ends i.e., from front or rear.
The details for the class deQueue are given below:
| Class name | deQueue |
|
Data members/instance variables: |
|
| Qrr[] | array to hold integer elements |
| lim | maximum capacity of the dequeue |
| front | to point the index of the front end |
| rear | to point the index of the rear end |
|
Methods/Member functions: |
|
| deQueue(int 1) | constructor to initialise lim = 1, front = 0 and rear =0 |
| void addFront(int v) | to add integers in the dequeue at the front end if possible, otherwise display the message “OVERFLOW FROM FRONT” |
| void addRear(int v) | to add integers in the dequeue at the rear end if possible, otherwise, display the message “OVERFLOW FROM REAR” |
| int popFront() | removes and returns the integers from the front end of the dequeue if any, else returns — 999 |
| int popRear ( ) | removes and returns the integers from the rear end of the dequeue if any, else returns — 999 |
| void show( ) | displays the elements of the dequeue |
Specify the class deQueue giving details of the function void addFront(int) and int popFront(). Assume that the other functions have been defined. The main() function and algorithm need NOT be written.
