-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update stack_using_linked_lists.c #620
Open
Shwetik
wants to merge
9
commits into
TheAlgorithms:master
Choose a base branch
from
Shwetik:patch-3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ddf671d
Update stack_using_linked_lists.c
Shwetik 9a70599
Update stack_using_linked_lists.c
Shwetik 8d63bec
Update stack_using_linked_lists.c
Shwetik e1bbff8
Update stack_using_linked_lists.c
Shwetik 7bb6d59
Update stack_using_linked_lists.c
Shwetik 12044c8
Update stack_using_linked_lists.c
Shwetik 400218f
Update data_structures/linked_list/stack_using_linked_lists.c
Shwetik 4d8bfe2
Update data_structures/linked_list/stack_using_linked_lists.c
Shwetik c75e9f2
Update data_structures/linked_list/stack_using_linked_lists.c
Shwetik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -36,40 +36,51 @@ int main() | |||||
} | ||||||
} | ||||||
|
||||||
void push(struct node *p) | ||||||
/** | ||||||
* 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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this empty whitespace.
Suggested change
|
||||||
printf("enter element to be inserted\n"); | ||||||
scanf("%d", &item); | ||||||
temp->info = item; | ||||||
|
||||||
temp->link = top; | ||||||
top = temp; | ||||||
top = temp; | ||||||
Shwetik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
printf("inserted succesfully\n"); | ||||||
} | ||||||
void pop(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) | ||||||
{ | ||||||
int item; | ||||||
struct node *temp; | ||||||
|
||||||
if (top == NULL) | ||||||
if (top == NULL) | ||||||
printf("stack is empty\n"); | ||||||
else | ||||||
{ | ||||||
item = top->info; | ||||||
temp = top; | ||||||
top = top->link; | ||||||
free(temp); | ||||||
top = top->link; | ||||||
free(temp); | ||||||
Shwetik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
printf("Element popped is%d\n", item); | ||||||
} | ||||||
} | ||||||
|
||||||
void display(struct node *p) | ||||||
{ | ||||||
if (top == NULL) | ||||||
if (top == NULL) | ||||||
Shwetik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
printf("stack is empty\n"); | ||||||
else | ||||||
{ | ||||||
|
@@ -79,6 +90,5 @@ void display(struct node *p) | |||||
printf("%d\n", p->info); | ||||||
p = p->link; | ||||||
} | ||||||
// printf("%d\n",p->info); | ||||||
} | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing parameter documentation.
Same in other parts of the code.