Skip to content

palindrome_in_singly_linked_list.c#3344

Open
iashreya wants to merge 5 commits intoOpenGenus:masterfrom
iashreya:master
Open

palindrome_in_singly_linked_list.c#3344
iashreya wants to merge 5 commits intoOpenGenus:masterfrom
iashreya:master

Conversation

@iashreya
Copy link

@iashreya iashreya commented Mar 1, 2018

Fixes issue:

Changes:

Copy link
Member

@arnavb arnavb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,58 @@
#include<stdio.h>
#include<stdlib.h>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid globals. Move variables to main and pass them around.


struct node
{
int info;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation.

{
int info;
struct node *link;
}*start = NULL, *ptr1 ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid globals.

struct node*temp, *ptr;

while(proceed == 1)
{ temp = (struct node *)malloc(sizeof(struct node));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

ptr1 = ptr1->link;
}

void main()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int. Also all types go on their own line according to our style guide.

create();
check(start);
if(flag == 1)
puts("PALINDROME");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use printf.

@@ -0,0 +1,58 @@
#include<stdio.h>
#include<stdlib.h>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made some changes, have a look.

struct node
{
int info;
struct node *link;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Statements should not be on same line as braces.

};

//Function for creating the linked list
struct node* create(struct node *start)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type goes on its own line.

temp->link = NULL;
puts("Enter info") ;
scanf("%d", &temp->info);
if(start == NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation fix here and below.

return(ptr_fwd->link);
}

void main()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int main. void should be the parameters.

struct node
{
int info;
struct node* link;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove 1 space from before link.


//Function for creating the linked list

struct node* create(struct node* start)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I repeat myself; Please fix the indentation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand what you are asking for. Please elaborate!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iashreya Looks like you have fixed it now. Good job!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

}

//Function to check if the list forms a palindrome or not
struct node* check(struct node *ptr_bck, struct node *ptr_fwd, int *f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type on its own line.

}

int main(void)
{ struct node *start = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this down a line.

return(ptr_fwd->link);
}

int main(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the type to its own line.

temp = (struct node *)malloc(sizeof(struct node));
temp->link = NULL;
puts("Enter info") ;
scanf("%d", &temp->info);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type goes on its own line for all functions. Eg:

struct node*
create(struct node* start)

@@ -0,0 +1,62 @@
#include<stdio.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename should be all lowercase + separated by underscores.

Copy link
Author

@iashreya iashreya Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By filename, do you mean "PalindromeInSinglyLinkedList.c" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iashreya Yes.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

return(ptr_fwd->link);
}

int main(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well.

@iashreya iashreya changed the title PalindromeInSinglyLinkedList.c palindrome_in_singly_linked_list.c Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants