From ed83531121a5e78b1ee34268a4e3eeac6629659e Mon Sep 17 00:00:00 2001 From: Ankitsh-rtx <79033610+Ankitsh-rtx@users.noreply.github.com> Date: Tue, 5 Oct 2021 11:15:29 +0530 Subject: [PATCH 1/2] updated indentation --- code.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code.cpp b/code.cpp index aa543b5..0a8ae0d 100644 --- a/code.cpp +++ b/code.cpp @@ -5,11 +5,11 @@ using namespace std; int main (){ int sum=0; - for(int i=0;i>arr[i]; - sum+=arr[i]; + for(int i = 0; i < n; i++ ){ + cin >> arr[i]; + sum += arr[i]; } - cout< Date: Tue, 5 Oct 2021 11:49:56 +0530 Subject: [PATCH 2/2] added Pop function pop function which deletes the topmost element --- likedlist.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/likedlist.c b/likedlist.c index b99503a..6419f03 100644 --- a/likedlist.c +++ b/likedlist.c @@ -40,6 +40,16 @@ int getCount(struct Node* head) } return count; } +/* deletes the topmost element in the linked list */ +void pop(struct Node **head_ref){ + struct Node * current = (*head_ref); + if(current !=NULL){ + (*head_ref) = (*head_ref)->next; + free(current); + } + else printf("Stack Underflow !!\n"); + +} /* Driver program to test count function*/ int main() @@ -57,5 +67,9 @@ int main() /* Check the count function */ printf("count of nodes is %d", getCount(head)); + + pop(&head); + printf("count of nodes is %d", getCount(head)); + return 0; }