Junior — Middle
Which design pattern provides a data structure in the form of a stack?
sobes.tech AI
Answer from AI
The design pattern that provides data structure in the form of a stack is Stack.
This pattern implements the LIFO (Last In, First Out) principle, where the last added element is retrieved first. In programming, a stack is often used for managing function calls, undo actions, etc.
Example in Java:
Stack<Integer> stack = new Stack<>();
stack.push(1); // add element
stack.push(2);
int top = stack.pop(); // retrieve the last added element (2)