Skip to content

Commit

Permalink
linkedlist.cpp: Remove space inconsistencies
Browse files Browse the repository at this point in the history
This commit removes the space inconsistencies detected by coala

Closes #369
  • Loading branch information
Rajeev R Menon committed Oct 7, 2018
1 parent 9ed6fc4 commit abafb42
Showing 1 changed file with 60 additions and 65 deletions.
125 changes: 60 additions & 65 deletions linked_list/cpp/linkedlist.cpp
Original file line number Diff line number Diff line change
@@ -1,87 +1,82 @@
#include <stdio.h>
#include <stdlib.h>

// A linked list node

struct Node
{
int data;
struct Node *next;
struct Node{
int data;
struct Node *next;
};
/*
Given a reference (pointer to pointer) to the head of a list
and an int, inserts a new node on the front of the list.
*/

void push(struct Node** head_ref, int new_data)
{
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
*/

void push(struct Node** head_ref, int new_data){
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}

/*
Given a reference (pointer to pointer) to the head of a list
and a position, deletes the node at the given position
*/

void deleteNode(struct Node **head_ref, int position)
{
// If linked list is empty
if (*head_ref == NULL)
return;
// Store head node
struct Node* temp = *head_ref;
// If head needs to be removed
if (position == 0)
{
*head_ref = temp->next;
free(temp);
return;
}

// Find previous node of the node to be deleted
for (int i = 0; temp != NULL && i < position - 1; i++)
temp = temp->next;
// If position is more than number of ndoes
if (temp == NULL || temp->next == NULL)
return;
// Node temp->next is the node to be deleted
// Store pointer to the next of node to be deleted
struct Node *next = temp->next->next;

// Unlink the node from linked list
free(temp->next);
temp->next = next;
void deleteNode(struct Node **head_ref, int position){
// If linked list is empty
if (*head_ref == NULL)
return;
// Store head node
struct Node* temp = *head_ref;
// If head needs to be removed
if (position == 0){
*head_ref = temp->next;
free(temp);
return;
}

// Find previous node of the node to be deleted
for (int i = 0; temp != NULL && i < position - 1; i++)
temp = temp->next;

// If position is more than number of ndoes
if (temp == NULL || temp->next == NULL)
return;

// Node temp->next is the node to be deleted
// Store pointer to the next of node to be deleted
struct Node *next = temp->next->next;

// Unlink the node from linked list
free(temp->next);
temp->next = next;
}

// This function prints contents of linked list starting from
// the given node
void printList(struct Node *node)
{
while (node != NULL)
{
printf(" %d ", node->data);
node = node->next;
}
void printList(struct Node *node){
while (node != NULL){
printf(" %d ", node->data);
node = node->next;
}
}

/* Drier program to test above functions*/
int main()
{
/* Start with the empty list */
struct Node* head = NULL;

push(&head, 7);
push(&head, 1);
push(&head, 3);
push(&head, 2);
push(&head, 8);

puts("Created Linked List: ");
printList(head);
deleteNode(&head, 4);
puts("\nLinked List after Deletion at position 4: ");
printList(head);
return 0;
int main(){
/* Start with the empty list */
struct Node* head = NULL;

push(&head, 7);
push(&head, 1);
push(&head, 3);
push(&head, 2);
push(&head, 8);

puts("Created Linked List: ");
printList(head);
deleteNode(&head, 4);
puts("\nLinked List after Deletion at position 4: ");
printList(head);
return 0;
}

1 comment on commit abafb42

@sangamcse
Copy link
Member

Choose a reason for hiding this comment

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

Comment on abafb42.

There are 31 results for the section all.cpplint. They have been shortened and will not be shown inline because they are more than 10.

Message File Line
Missing space before { [whitespace/braces] [5] linked_list/cpp/linkedlist.cpp 14
Missing space before { [whitespace/braces] [5] linked_list/cpp/linkedlist.cpp 26
Missing space before { [whitespace/braces] [5] linked_list/cpp/linkedlist.cpp 33
Missing space before { [whitespace/braces] [5] linked_list/cpp/linkedlist.cpp 58
Missing space before { [whitespace/braces] [5] linked_list/cpp/linkedlist.cpp 59
Missing space before { [whitespace/braces] [5] linked_list/cpp/linkedlist.cpp 66
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 1
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 2
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 4
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 8
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 9
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 10
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 11
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 19
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 20
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 21
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 22
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 23
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 24
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 25
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 49
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 54
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 55
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 56
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 57
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 63
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 64
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 65
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 74
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 81
Unexpected \r (^M) found; better to use only \n [whitespace/newline] [1] linked_list/cpp/linkedlist.cpp 82

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

Please sign in to comment.