A simple C implementation of a stack using a linked list.
main.c– demonstration programStack.c– stack operationsheader.h– structure and function declarations
Run the following command to compile the project:
gcc main.c Stack.c -o stack_programRun the compiled executable:
./stack_programBelow is a small block diagram showing how the project components interact and how the stack is represented internally (linked list of nodes).
graph LR
main[main.c] --> api["Stack API<br/> (push / pop / peek)"]
api --> stack["Stack (Linked List)"]
stack --> node1["Node<br/>{data, next}"]
node1 --> node2["Node<br/>{data, next}"]
node2 --> null["NULL"]
And a simple ASCII view of the linked list (top is leftmost):
top -> [data | next] -> [data | next] -> NULL