From ddf671df55b86bb540887bcca18b9202783b7f13 Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 02:07:27 +0530 Subject: [PATCH 1/9] Update stack_using_linked_lists.c Added comments and time complexities. --- .../linked_list/stack_using_linked_lists.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index 4bbd7c2d9f..45d0f309bc 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -36,40 +36,40 @@ int main() } } -void push(struct node *p) +void push(struct node *p) // push function will add a new node at the head of the list, time complexity O(1). { int item; struct node *temp; - temp = (struct node *)malloc(sizeof(struct node)); + temp = (struct node *)malloc(sizeof(struct node)); //creating memory for temp node. printf("enter element to be inserted\n"); scanf("%d", &item); temp->info = item; temp->link = top; - top = temp; + top = temp; //top of the stack points to newly added node. printf("inserted succesfully\n"); } -void pop(struct node *p) +void pop(struct node *p) // pop function deletes the first node from the head, time complexity O(1). { int item; struct node *temp; - if (top == NULL) + if (top == NULL) // Underflow condition printf("stack is empty\n"); else { item = top->info; temp = top; - top = top->link; - free(temp); + top = top->link; // new top will be the node pointed by previous top. + free(temp); // free the memory of node using free(). printf("Element popped is%d\n", item); } } void display(struct node *p) { - if (top == NULL) + if (top == NULL) // Underflow condition printf("stack is empty\n"); else { @@ -79,6 +79,5 @@ void display(struct node *p) printf("%d\n", p->info); p = p->link; } - // printf("%d\n",p->info); } } From 9a7059935b308a63a43e7774e9a615a95e2c370e Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 04:14:46 +0530 Subject: [PATCH 2/9] Update stack_using_linked_lists.c --- .../linked_list/stack_using_linked_lists.c | 11 +++++++++-- 1 file changed, 9 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 45d0f309bc..1214ce9c8d 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -36,7 +36,10 @@ int main() } } -void push(struct node *p) // push function will add a new node at the head of the list, time complexity O(1). +/** + * push function will add a new node at the head of the list, time complexity O(1). + */ +void push(struct node *p) { int item; struct node *temp; @@ -50,7 +53,11 @@ void push(struct node *p) // push function will add a new node at the head of th printf("inserted succesfully\n"); } -void pop(struct node *p) // pop function deletes the first node from the head, time complexity O(1). + +/** + * pop function deletes the first node from the head, time complexity O(1). + */ +void pop(struct node *p) { int item; struct node *temp; From 8d63bece2ec9be1e08ccb30139bb19cbd95451bd Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 04:35:58 +0530 Subject: [PATCH 3/9] Update stack_using_linked_lists.c --- data_structures/linked_list/stack_using_linked_lists.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index 1214ce9c8d..c15599e5a0 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -43,7 +43,7 @@ void push(struct node *p) { int item; struct node *temp; - temp = (struct node *)malloc(sizeof(struct node)); //creating memory for temp node. + temp = (struct node *)malloc(sizeof(struct node)); printf("enter element to be inserted\n"); scanf("%d", &item); temp->info = item; @@ -62,21 +62,21 @@ void pop(struct node *p) int item; struct node *temp; - if (top == NULL) // Underflow condition + if (top == NULL) printf("stack is empty\n"); else { item = top->info; temp = top; - top = top->link; // new top will be the node pointed by previous top. - free(temp); // free the memory of node using free(). + top = top->link; + free(temp); printf("Element popped is%d\n", item); } } void display(struct node *p) { - if (top == NULL) // Underflow condition + if (top == NULL) printf("stack is empty\n"); else { From e1bbff808bdeee391b849dec310a9fba5b1d33a3 Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 04:44:44 +0530 Subject: [PATCH 4/9] Update stack_using_linked_lists.c --- data_structures/linked_list/stack_using_linked_lists.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index c15599e5a0..405d4b068f 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -38,6 +38,8 @@ int main() /** * push function will add a new node at the head of the list, time complexity O(1). + * @param p pointer to the top of the stack. + * @returns void. */ void push(struct node *p) { @@ -56,6 +58,8 @@ void push(struct node *p) /** * pop function deletes the first node from the head, time complexity O(1). + * @param p pointer to the top of the stack. + * @returns void. */ void pop(struct node *p) { From 7bb6d594e8e914216e4828a797344e00ff009431 Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 04:45:31 +0530 Subject: [PATCH 5/9] Update stack_using_linked_lists.c --- data_structures/linked_list/stack_using_linked_lists.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index 405d4b068f..673da9bb02 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -51,7 +51,7 @@ void push(struct node *p) temp->info = item; temp->link = top; - top = temp; //top of the stack points to newly added node. + top = temp; printf("inserted succesfully\n"); } From 12044c8d195768efca1b31be9ccc4a1ca67a06b1 Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:12:04 +0530 Subject: [PATCH 6/9] Update stack_using_linked_lists.c --- .../linked_list/stack_using_linked_lists.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index 673da9bb02..1793cd0008 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -37,15 +37,15 @@ int main() } /** - * push function will add a new node at the head of the list, time complexity O(1). - * @param p pointer to the top of the stack. - * @returns void. + * push function will add a new node at the head of the list, time complexity O(1) + * @param p pointer to the top of the stack + * @returns void */ void push(struct node *p) { int item; struct node *temp; - temp = (struct node *)malloc(sizeof(struct node)); + temp = (struct node *)malloc(sizeof(struct node)); printf("enter element to be inserted\n"); scanf("%d", &item); temp->info = item; @@ -57,16 +57,16 @@ void push(struct node *p) } /** - * pop function deletes the first node from the head, time complexity O(1). - * @param p pointer to the top of the stack. - * @returns void. + * pop function deletes the first node from the head, time complexity O(1) + * @param p pointer to the top of the stack + * @returns void */ -void pop(struct node *p) +void pop(struct node *p) { int item; struct node *temp; - if (top == NULL) + if (top == NULL) printf("stack is empty\n"); else { From 400218f5e69ff7eb9012c093984db8299295b218 Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:19:14 +0530 Subject: [PATCH 7/9] Update data_structures/linked_list/stack_using_linked_lists.c Co-authored-by: David Leal --- data_structures/linked_list/stack_using_linked_lists.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index 1793cd0008..6204e739b8 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -51,7 +51,7 @@ void push(struct node *p) temp->info = item; temp->link = top; - top = temp; + top = temp; printf("inserted succesfully\n"); } From 4d8bfe2ec9fd4159c9422fa6e5664a2624b40a96 Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:19:29 +0530 Subject: [PATCH 8/9] Update data_structures/linked_list/stack_using_linked_lists.c Co-authored-by: David Leal --- data_structures/linked_list/stack_using_linked_lists.c | 4 ++-- 1 file changed, 2 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 6204e739b8..ec1e417530 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -72,8 +72,8 @@ void pop(struct node *p) { item = top->info; temp = top; - top = top->link; - free(temp); + top = top->link; + free(temp); printf("Element popped is%d\n", item); } } From c75e9f26f46e955fe64a0796b52138b9afae7f3f Mon Sep 17 00:00:00 2001 From: Shezza221b <41204318+Shezza221b@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:19:38 +0530 Subject: [PATCH 9/9] Update data_structures/linked_list/stack_using_linked_lists.c Co-authored-by: David Leal --- data_structures/linked_list/stack_using_linked_lists.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/linked_list/stack_using_linked_lists.c b/data_structures/linked_list/stack_using_linked_lists.c index ec1e417530..0e10554af3 100644 --- a/data_structures/linked_list/stack_using_linked_lists.c +++ b/data_structures/linked_list/stack_using_linked_lists.c @@ -80,7 +80,7 @@ void pop(struct node *p) void display(struct node *p) { - if (top == NULL) + if (top == NULL) printf("stack is empty\n"); else {