-
Notifications
You must be signed in to change notification settings - Fork 302
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
linkedlist.cpp: Add linkedlist implementation in C++ #375
Conversation
This adds linked list implementation in C++. This includes insertion, deletion from any specified position as well as printing of the entire list Closes #369
linked_list/cpp/linkedlist.cpp
Outdated
{ | ||
// If linked list is empty | ||
if (*head_ref == NULL) | ||
return; |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -29,7 +29,7 @@
{
// If linked list is empty
if (*head_ref == NULL)
- return;
+ return;
// Store head node
struct Node* temp = *head_ref;
// If head needs to be removed
linked_list/cpp/linkedlist.cpp
Outdated
// If head needs to be removed | ||
if (position == 0) | ||
{ | ||
*head_ref = temp->next; |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -35,7 +35,7 @@
// If head needs to be removed
if (position == 0)
{
- *head_ref = temp->next;
+ *head_ref = temp->next;
free(temp);
return;
}
linked_list/cpp/linkedlist.cpp
Outdated
if (position == 0) | ||
{ | ||
*head_ref = temp->next; | ||
free(temp); |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -36,7 +36,7 @@
if (position == 0)
{
*head_ref = temp->next;
- free(temp);
+ free(temp);
return;
}
linked_list/cpp/linkedlist.cpp
Outdated
{ | ||
*head_ref = temp->next; | ||
free(temp); | ||
return; |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -37,7 +37,7 @@
{
*head_ref = temp->next;
free(temp);
- return;
+ return;
}
// Find previous node of the node to be deleted
linked_list/cpp/linkedlist.cpp
Outdated
|
||
// Find previous node of the node to be deleted | ||
for (int i = 0; temp != NULL && i < position - 1; i++) | ||
temp = temp->next; |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -42,7 +42,7 @@
// Find previous node of the node to be deleted
for (int i = 0; temp != NULL && i < position - 1; i++)
- temp = temp->next;
+ temp = temp->next;
// If position is more than number of ndoes
if (temp == NULL || temp->next == NULL)
return;
linked_list/cpp/linkedlist.cpp
Outdated
temp = temp->next; | ||
// If position is more than number of ndoes | ||
if (temp == NULL || temp->next == NULL) | ||
return; |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -45,7 +45,7 @@
temp = temp->next;
// If position is more than number of ndoes
if (temp == NULL || temp->next == NULL)
- return;
+ 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;
linked_list/cpp/linkedlist.cpp
Outdated
{ | ||
while (node != NULL) | ||
{ | ||
printf(" %d ", node->data); |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -61,7 +61,7 @@
{
while (node != NULL)
{
- printf(" %d ", node->data);
+ printf(" %d ", node->data);
node = node->next;
}
}
linked_list/cpp/linkedlist.cpp
Outdated
while (node != NULL) | ||
{ | ||
printf(" %d ", node->data); | ||
node = node->next; |
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.
Line contains following spacing inconsistencies:
- Spaces used instead of tabs.
Origin: SpaceConsistencyBear, Section: all.cpp
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
+++ b/tmp/tmpik7n2ih_/linked_list/cpp/linkedlist.cpp
@@ -62,7 +62,7 @@
while (node != NULL)
{
printf(" %d ", node->data);
- node = node->next;
+ node = node->next;
}
}
linked_list/cpp/linkedlist.cpp
Outdated
// A linked list node | ||
|
||
struct Node | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
linked_list/cpp/linkedlist.cpp
Outdated
*/ | ||
|
||
void push(struct Node** head_ref, int new_data) | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
linked_list/cpp/linkedlist.cpp
Outdated
*/ | ||
|
||
void deleteNode(struct Node **head_ref, int position) | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
linked_list/cpp/linkedlist.cpp
Outdated
struct Node* temp = *head_ref; | ||
// If head needs to be removed | ||
if (position == 0) | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
linked_list/cpp/linkedlist.cpp
Outdated
// This function prints contents of linked list starting from | ||
// the given node | ||
void printList(struct Node *node) | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
linked_list/cpp/linkedlist.cpp
Outdated
void printList(struct Node *node) | ||
{ | ||
while (node != NULL) | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
linked_list/cpp/linkedlist.cpp
Outdated
|
||
/* Drier program to test above functions*/ | ||
int main() | ||
{ |
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.
{ should almost always be at the end of the previous line [whitespace/braces] [4]
Origin: CPPLintBear, Section: all.cpplint
.
This commit removes the space inconsistencies detected by coala Closes #369
Fixes #369
This adds linked list implementation in C++. This includes
insertion, deletion from any specified position as well as
printing of the entire list
Closes #369
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Fixes #{ISSUE_NUMBER}
By submitting this pull request I confirm I've read and complied with the
below declarations.
{Tag}: Add {Algorithm/DS name} [{Language}]
, notUpdate README.md
orAdded new code
.After you submit your pull request, DO NOT click the 'Update Branch' button.