Problem Statement
Stack data structure cannot be used for which of the following?
Explanation
Resource allocation and scheduling typically require a queue data structure that follows First In First Out principle, not a stack. Tasks or resources need to be processed in the order they arrive for fair scheduling.
Stacks are excellent for expression evaluation because operators and operands can be processed using Last In First Out order. String reversal works by pushing characters onto a stack and popping them in reverse order. Recursion naturally uses the call stack to maintain function contexts.
Code Solution
SolutionRead Only
// Stack - LIFO (Last In First Out)
Stack<String> stack = new Stack<>();
stack.push("First");
stack.push("Second");
stack.pop(); // Returns "Second" (last in, first out)
// Queue - FIFO for resource scheduling
Queue<String> queue = new LinkedList<>();
queue.add("First");
queue.add("Second");
queue.poll(); // Returns "First" (first in, first out)
// Resource scheduling needs FIFO, not LIFO