Practice 50 C# Stack Programming Questions, TechnoVlogs

Practice 50 C# Stack Programming Questions


Q1. Write a C# program to implement a stack using arrays.  
  Input: Push 10, 20, 30  
  Output: Stack = [10, 20, 30]

Q2. Write a C# program to implement push and pop operations on a stack.  
  Input: Push 10, 20, Pop  
  Output: Stack = [10]

Q3. Write a C# program to check if a stack is empty.  
  Input: Stack = [ ]  
  Output: Stack is empty

Q4. Write a C# program to find the top element of the stack.  
  Input: Push 10, 20, 30  
  Output: Top element = 30

Q5. Write a C# program to implement a stack using a linked list.  
  Input: Push 5, 10, 15  
  Output: Stack = [5, 10, 15]

Q6. Write a C# program to pop an element from the stack and display it.  
  Input: Push 1, 2, 3, Pop  
  Output: Popped element = 3, Stack = [1, 2]

Q7. Write a C# program to implement a stack and check if it is full.  
  Input: Push 10, 20, 30  
  Output: Stack is not full

Q8. Write a C# program to count the number of elements in the stack.  
  Input: Push 10, 20, 30  
  Output: Number of elements = 3

Q9. Write a C# program to reverse a string using a stack.  
  Input: string = "Hello"  
  Output: Reversed string = "olleH"

Q10. Write a C# program to check if the parentheses in a string are balanced using a stack.  
   Input: string = "(a + b)"  
   Output: Balanced

Q11. Write a C# program to implement a stack using a dynamic array.  
   Input: Push 5, 10, 15  
   Output: Stack = [5, 10, 15]

Q12. Write a C# program to simulate the working of a stack using an array of fixed size.  
   Input: Push 1, 2, 3, 4  
   Output: Stack = [1, 2, 3, 4]

Q13. Write a C# program to implement a stack that supports both push and pop operations with size limit.  
   Input: Push 5, 10, 15, Pop  
   Output: Stack = [5, 10]

Q14. Write a C# program to check if a number is palindrome using a stack.  
   Input: number = 121  
   Output: Palindrome

Q15. Write a C# program to implement a stack and display all elements using a loop.  
   Input: Push 5, 10, 15  
   Output: Stack elements = 5 10 15

Q16. Write a C# program to find the minimum element in the stack.  
   Input: Push 10, 5, 20  
   Output: Minimum element = 5

Q17. Write a C# program to implement a stack that tracks the minimum element efficiently.  
   Input: Push 10, 20, 5, 15  
   Output: Minimum element = 5

Q18. Write a C# program to implement a stack and perform a multiple push and pop operations.  
   Input: Push 10, 20, Pop, Push 30, Pop  
   Output: Stack = [10, 30]

Q19. Write a C# program to convert a decimal number to binary using a stack.  
   Input: Decimal = 10  
   Output: Binary = 1010

Q20. Write a C# program to check if a string has balanced curly braces using a stack.  
   Input: string = "{a + b}"  
   Output: Balanced

Q21. Write a C# program to implement a stack and check if a value exists in the stack.  
   Input: Push 10, 20, 30, value = 20  
   Output: Value found

Q22. Write a C# program to implement the peek operation of a stack.  
   Input: Push 10, 20, Peek  
   Output: Top element = 20

Q23. Write a C# program to implement a stack and check if it is full or empty.  
   Input: Push 10, 20, 30  
   Output: Stack is not full

Q24. Write a C# program to implement a stack using a generic collection.  
   Input: Push 5, 10, 15  
   Output: Stack = [5, 10, 15]

Q25. Write a C# program to implement a stack and perform multiple operations based on user input.  
   Input: Push 10, Pop, Push 20, Peek  
   Output: Top element = 20

Q26. Write a C# program to implement a stack and print all elements after performing pop operations.  
   Input: Push 1, 2, 3, Pop, Pop  
   Output: Stack = [1]

Q27. Write a C# program to implement a stack and check if an element is at the top of the stack.  
   Input: Push 10, 20, 30, Element = 20  
   Output: Element not at the top

Q28. Write a C# program to implement a stack and remove all elements.  
   Input: Push 5, 10, 15, Pop, Pop, Pop  
   Output: Stack = [ ]

Q29. Write a C# program to check if an element exists in the stack using a search operation.  
   Input: Push 1, 2, 3, Element = 2  
   Output: Element found

Q30. Write a C# program to implement a stack and display its size after several operations.  
   Input: Push 10, 20, Pop  
   Output: Stack size = 1

Q31. Write a C# program to find the sum of all elements in a stack.  
   Input: Push 10, 20, 30  
   Output: Sum = 60

Q32. Write a C# program to find the product of all elements in a stack.  
   Input: Push 2, 3, 4  
   Output: Product = 24

Q33. Write a C# program to implement a stack and clear all elements.  
   Input: Push 5, 10, 15, Clear  
   Output: Stack is empty

Q34. Write a C# program to check if the stack is full using a size constraint.  
   Input: Stack size = 3, Push 1, 2, 3  
   Output: Stack is full

Q35. Write a C# program to implement a stack that supports undo and redo operations.  
   Input: Push 10, Push 20, Undo, Redo  
   Output: Top element = 20

Q36. Write a C# program to check if the stack contains duplicate elements.  
   Input: Push 1, 2, 2, 3  
   Output: Stack contains duplicates

Q37. Write a C# program to implement a stack that can store multiple data types.  
   Input: Push 1, "Hello", 3.14  
   Output: Stack = [1, "Hello", 3.14]

Q38. Write a C# program to implement a stack that supports both push and pop operations in reverse order.  
   Input: Push 1, 2, 3, Pop  
   Output: Popped element = 3

Q39. Write a C# program to implement a stack and return true if the stack is empty.  
   Input: Stack = [ ]  
   Output: Stack is empty

Q40. Write a C# program to implement a stack and perform push and pop operations based on user choice.  
   Input: Push 10, 20, Pop  
   Output: Stack = [10]

Q41. Write a C# program to check if a number is divisible by 3 using a stack.  
   Input: number = 9  
   Output: Divisible by 3

Q42. Write a C# program to find the average of elements in a stack.  
   Input: Push 10, 20, 30  
   Output: Average = 20

Q43. Write a C# program to check if the stack contains only unique elements.  
   Input: Push 1, 2, 2, 3  
   Output: Stack contains duplicates

Q44. Write a C# program to implement a stack that tracks the maximum element efficiently.  
   Input: Push 10, 20, 5, 30  
   Output: Maximum element = 30

Q45. Write a C# program to implement a stack and print the elements from top to bottom.  
   Input: Push 1, 2, 3  
   Output: Stack = 3 2 1

Q46. Write a C# program to check if a number is even or odd using a stack.  
   Input: number = 4  
   Output: Even

Q47. Write a C# program to implement a stack and display the second element from the top.  
   Input: Push 5, 10, 15  
   Output: Second element = 10

Q48. Write a C# program to implement a stack and display the entire stack after performing multiple operations.  
   Input: Push 1, 2, 3, Pop, Push 4  
   Output: Stack = [1, 4]

Q49. Write a C# program to check if the stack is full when it has reached its limit.  
   Input: Stack size = 3, Push 10, 20, 30  
   Output: Stack is full

50. Write a C# program to implement a stack and calculate the difference between the maximum and minimum elements.  
   Input: Push 10, 20, 5  
   Output: Difference = 15

Share on Social Media