C
C copied to clipboard
Refactor stack implementation using global top pointer
This pull request refactors the stack implementation in Program.c from a function-based approach using root pointers to a simpler global-pointer design and introduces a menu-driven interface for user interaction. The changes improve usability and code clarity by consolidating stack operations and providing interactive options.
Refactoring and simplification of stack operations:
- Replaced the previous function-based stack implementation (using root pointers and helper functions like
newNode,isEmpty, andpeek) with a globaltoppointer and direct stack manipulation functions:push,pop, anddisplay. - Simplified
pushandpopfunctions to operate directly on the globaltoppointer, removing the need to pass pointers and return values.
User interface improvements:
- Added a menu-driven loop in
mainto allow users to interactively push, pop, and display stack elements, with clear prompts and feedback for each operation. - Implemented a new
displayfunction to show all stack elements, enhancing visibility of stack contents during program execution.