Chapter 10: Data Structures - II: Stacks and Queues
Chapter 10: Data Structures - II: Stacks and Queues
Type C: Programming Practice/ Knowledge based Questions
1. Write a program that depending upon user's choice, either pushes or pops an element in a stack.
2. A line of text is read from the input terminal into a stack. Write a program to output the string in the reverse order, each character appearing twice.
2. A line of text is read from the input terminal into a stack. Write a program to output the string in the reverse order, each character appearing twice.
(e.g., the string a b c d e should be changed to ee dd cc bb aa )
3. Write a program that depending upon user's choice, either pushes or pops an element in a stack. The elements are shifted towards right so that top always remains at 0th (zeroth) index.
(N.B: If the elements are shifted downwards or towards right side, then unused free spaces are available at the beginning of the list otherwise free space is available at the end of the list)
4. Write a program to insert or delete an element from a queue depending upon user's choice. The elements are not shifted after insertion or deletion.
5. Write a program to insert or delete an element from a queue depending upon user's choice.
(N.B: shifting the elements towards the right so that rear always remains at the 0th index)
6. Write a program to implement input-restricted deque. (Both the operations i.e., insertions and deletions should be taken care of.)
7. Each node of a STACK contains the following information:
(i) Pin code of a city,
(ii) Name of city.
Write a program to implement following operations in above stack
(a) PUSH( ) To push a node in to the stack.
(b) POP( ) To remove a node from the stack.
8. Write a program that implements three queues namely HighestPr, NormalPr and LowestPr.
The program accepts an element along with its priority from the user, e.g.,
Enter element: KP213
Priority (Highest/ Normal/ Lowest(H/N/L)): H
As per priority entered, the element is added in the corresponding queue.
A menu offers following options:
1. Insert Element
2. Search for Element
3. Change Priority
For option 1, element is inserted in one queue as described above.
For option 2, ask for an element and search for it in all three queues. If found, display its queue name, otherwise display "Element not found".
For option 3, ask for an element, if it exists in a queue, ask for its new priority as:
Want to Increase/ Decrease its priority (I/ D)? I
And then remove the element from its existing queue and add it to the new queue as per the changed priority.
(NB: for option 3 if the element (whose priority needs to be changed) is situated at the end of the queue say rear then all of the elements are popped off from the front end and added to the rear until we reach that element)
Thankyou .... Its helping😊
ReplyDeleteHappy to hear that :)
DeleteGreat effort. Thanks a lot it helped me. Could u also post answers for Q8. Also for question 3 is it possible that I can provide u with a solution that I found.
ReplyDeleteI meant Q5. Sorry
DeleteSolution for Question 8 is posted enjoy, regarding question 5 it is same as question 4 unless it wants us to use shifting which I thought of adding but never did which I am fixing right now :). And if you want you can share your own solution for it as a pastebin link here :) i will look into it and add it as an alternate solution if it is not the same as mine :)
Delete