Skip to content
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

Closed
wants to merge 2 commits into from
Closed

linkedlist.cpp: Add linkedlist implementation in C++ #375

wants to merge 2 commits into from

Conversation

rajeevrmenon97
Copy link

@rajeevrmenon97 rajeevrmenon97 commented Oct 7, 2018

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.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the commit guidelines for this project.
  • My code follows the standard code structure.
  • This pull request has a descriptive title. For example, {Tag}: Add {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.
  • This pull request shall only be reviewed and merged once all the checks passes. No maintainer or supporter shall be obliged to review it before this condition is met.
  • I have mentioned the issue number correctly (with hyperlink) in this pull request description.

After you submit your pull request, DO NOT click the 'Update Branch' button.

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
{
// If linked list is empty
if (*head_ref == NULL)
return;
Copy link
Member

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

// If head needs to be removed
if (position == 0)
{
*head_ref = temp->next;
Copy link
Member

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;
   }

if (position == 0)
{
*head_ref = temp->next;
free(temp);
Copy link
Member

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;
   }
 

{
*head_ref = temp->next;
free(temp);
return;
Copy link
Member

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


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

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;

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

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;

{
while (node != NULL)
{
printf(" %d ", node->data);
Copy link
Member

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;
   }
 }

while (node != NULL)
{
printf(" %d ", node->data);
node = node->next;
Copy link
Member

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;
   }
 }
 

// A linked list node

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.

{ should almost always be at the end of the previous line [whitespace/braces] [4]

Origin: CPPLintBear, Section: all.cpplint.

*/

void push(struct Node** head_ref, int new_data)
{
Copy link
Member

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.

*/

void deleteNode(struct Node **head_ref, int position)
{
Copy link
Member

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.

struct Node* temp = *head_ref;
// If head needs to be removed
if (position == 0)
{
Copy link
Member

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 function prints contents of linked list starting from
// the given node
void printList(struct Node *node)
{
Copy link
Member

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.

void printList(struct Node *node)
{
while (node != NULL)
{
Copy link
Member

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.


/* Drier program to test above functions*/
int main()
{
Copy link
Member

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
@sangamcse sangamcse added duplicate This issue or pull request already exists and removed difficulty/low enhancement New feature or request hacktoberfest HACKTOBERFEST 2020 type/data structure labels Oct 7, 2018
@sangamcse sangamcse closed this Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists process/pending_review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding linked list in C++
2 participants