Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a program to demonstrate the use of templates by creating a simple generic stack.

Hard

Problem Statement

Write a program to demonstrate the use of templates by creating a simple generic stack.

Sample Input

Stack<int> intStack; intStack.push(10);

Sample Output

Popped element: 10

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <iostream> template <typename T> class Stack { private: T *arr; int top; int capacity; public: Stack(); void push(T x); T pop(); }; int main() { // Logic to demonstrate template usage return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
Stack<int> intStack; intStack.push(10);
Expected Output
Popped element: 10