How it works...
First, a structure is defined, called a node, that consists of two members: one is the data and the other is a pointer called next. Because we want our stack to only store integer values, the data member of the structure is defined as an integer for storing integers and the next pointer is used to connect other nodes. Initially, the top pointer is set to NULL.
A while loop is set to execute, within which a menu is displayed. The menu is set to display three options: 1, to push into the stack; 2, to pop from the stack; and 3, to quit. Until the user enters 3 in the menu, the while loop will continue executing and keep displaying the menu, prompting the user to enter the desired option. If the user enters 1 to push a value to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access