palindrome_in_singly_linked_list.c#3344
palindrome_in_singly_linked_list.c#3344iashreya wants to merge 5 commits intoOpenGenus:masterfrom iashreya:master
Conversation
arnavb
left a comment
There was a problem hiding this comment.
https://github.com/OpenGenus/cosmos/blob/master/guides/coding_style/c/README.md <--- Please follow our C Style Guide.
| @@ -0,0 +1,58 @@ | |||
| #include<stdio.h> | |||
| #include<stdlib.h> | |||
There was a problem hiding this comment.
I've made some changes, have a look.
| @@ -0,0 +1,58 @@ | |||
| #include<stdio.h> | |||
| #include<stdlib.h> | |||
| int count = 0, flag = 1, *f = &flag; | |||
There was a problem hiding this comment.
Avoid globals. Move variables to main and pass them around.
|
|
||
| struct node | ||
| { | ||
| int info; |
| { | ||
| int info; | ||
| struct node *link; | ||
| }*start = NULL, *ptr1 ; |
| struct node*temp, *ptr; | ||
|
|
||
| while(proceed == 1) | ||
| { temp = (struct node *)malloc(sizeof(struct node)); |
| ptr1 = ptr1->link; | ||
| } | ||
|
|
||
| void main() |
There was a problem hiding this comment.
int. Also all types go on their own line according to our style guide.
| create(); | ||
| check(start); | ||
| if(flag == 1) | ||
| puts("PALINDROME"); |
| @@ -0,0 +1,58 @@ | |||
| #include<stdio.h> | |||
| #include<stdlib.h> | |||
There was a problem hiding this comment.
I've made some changes, have a look.
| struct node | ||
| { | ||
| int info; | ||
| struct node *link; |
There was a problem hiding this comment.
Inconsistency with *. Should be struct node* link, unless the style guide says otherwise.
|
|
||
| //Function for creating the linked list | ||
| struct node* create(struct node *start) | ||
| { int proceed = 1; |
There was a problem hiding this comment.
Statements should not be on same line as braces.
| }; | ||
|
|
||
| //Function for creating the linked list | ||
| struct node* create(struct node *start) |
| temp->link = NULL; | ||
| puts("Enter info") ; | ||
| scanf("%d", &temp->info); | ||
| if(start == NULL) |
| return(ptr_fwd->link); | ||
| } | ||
|
|
||
| void main() |
There was a problem hiding this comment.
int main. void should be the parameters.
| struct node | ||
| { | ||
| int info; | ||
| struct node* link; |
|
|
||
| //Function for creating the linked list | ||
|
|
||
| struct node* create(struct node* start) |
There was a problem hiding this comment.
Remove indent.
Move struct node* to its own line.
| temp = (struct node *)malloc(sizeof(struct node)); | ||
| temp->link = NULL; | ||
| puts("Enter info") ; | ||
| scanf("%d", &temp->info); |
There was a problem hiding this comment.
I repeat myself; Please fix the indentation.
There was a problem hiding this comment.
I do not understand what you are asking for. Please elaborate!
There was a problem hiding this comment.
@iashreya Looks like you have fixed it now. Good job!
| } | ||
|
|
||
| //Function to check if the list forms a palindrome or not | ||
| struct node* check(struct node *ptr_bck, struct node *ptr_fwd, int *f) |
| } | ||
|
|
||
| int main(void) | ||
| { struct node *start = NULL; |
| return(ptr_fwd->link); | ||
| } | ||
|
|
||
| int main(void) |
| temp = (struct node *)malloc(sizeof(struct node)); | ||
| temp->link = NULL; | ||
| puts("Enter info") ; | ||
| scanf("%d", &temp->info); |
There was a problem hiding this comment.
@iashreya Looks like you have fixed it now. Good job!
| struct node* link; | ||
| }; | ||
| //Function for creating the linked list | ||
| struct node* create(struct node* start) |
There was a problem hiding this comment.
The type goes on its own line for all functions. Eg:
struct node*
create(struct node* start)| @@ -0,0 +1,62 @@ | |||
| #include<stdio.h> | |||
There was a problem hiding this comment.
The filename should be all lowercase + separated by underscores.
There was a problem hiding this comment.
By filename, do you mean "PalindromeInSinglyLinkedList.c" ?
| return(start); | ||
| } | ||
| //Function to check if the list forms a palindrome or not | ||
| struct node* check(struct node *ptr_bck, struct node *ptr_fwd, int *f) |
| return(ptr_fwd->link); | ||
| } | ||
|
|
||
| int main(void) |
Fixes issue:
Changes: