Skip to content

maryam-narimi/StackDemo-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stack Implementation (Push & Pop) – Data Structures & Algorithms

This Java program demonstrates the implementation of a Stack data structure with basic operations: Push (add an element) and Pop (remove the top element). The program allows user interaction via a simple menu to perform stack operations and display the current stack contents.

Features

  • Add elements to the stack (Push)
  • Remove the top element from the stack (Pop)
  • Display all elements in the stack
  • Handles stack overflow and underflow situations

How to Run

  1. Open the project in NetBeans or any Java IDE.
  2. Make sure both StackDemo.java and Main.java are in the same package.
  3. Build the project.
  4. Run the Main class.
  5. Follow the menu prompts in the console to perform stack operations.


Enter stack size: 5

--- Stack Menu ---
1. Push
2. Pop
3. Display
4. Exit
Choose an option: 1
Enter a number to push: 10
10 pushed onto stack.

--- Stack Menu ---
1. Push
2. Pop
3. Display
4. Exit
Choose an option: 1
Enter a number to push: 20
20 pushed onto stack.

--- Stack Menu ---
1. Push
2. Pop
3. Display
4. Exit
Choose an option: 3
Stack elements: 10 20

--- Stack Menu ---
1. Push
2. Pop
3. Display
4. Exit
Choose an option: 2
20 popped from stack.

--- Stack Menu ---
1. Push
2. Pop
3. Display
4. Exit
Choose an option: 3
Stack elements: 10

--- Stack Menu ---
1. Push
2. Pop
3. Display
4. Exit
Choose an option: 4
Exiting program...

Course

Data Structures and Algorithms


Author

Maryam Narimi

About

Java project for Stack push/pop operations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages