From f9025f9da6e81cdd1365b443778263a922c31082 Mon Sep 17 00:00:00 2001 From: Heet0804 Date: Thu, 18 Dec 2025 18:02:52 +0530 Subject: [PATCH] Add documentation comments to stack using linked list implementation --- .../linked_list/stack_using_linked_lists.c | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index a3c473a72c..5e3ff82465 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -1,3 +1,29 @@ +/* + * Stack using Linked List + * ----------------------- + * This program implements a stack data structure using a singly linked list. + * + * Operations supported: + * 1. Push - Insert an element at the top of the stack + * 2. Pop - Remove the top element from the stack + * 3. Peek - View the top element without removing it + * 4. Display - Print all elements of the stack + * + * Advantages of Linked List Stack: + * - Dynamic size (no fixed capacity) + * - Efficient push and pop operations (O(1)) + * + * Time Complexity: + * Push : O(1) + * Pop : O(1) + * Peek : O(1) + * + * Space Complexity: + * O(n), where n is the number of elements in the stack + * + * Author: Open Source Contributor + */ + #include #include struct node @@ -35,7 +61,7 @@ int main() } } } - +//Pushes an element on the top of the Stack void push(struct node *p) { int item; @@ -50,6 +76,7 @@ void push(struct node *p) printf("Inserted successfully.\n"); } +//Pops the topmost Element void pop(struct node *p) { int item; @@ -66,7 +93,7 @@ void pop(struct node *p) printf("\nElement popped is %d.\n", item); } } - +//Displays all the Elements of the stack void display(struct node *p) { if (top == NULL)