Skip to content

I think the method in SinglyLinkedList is not right implementation, #2938

Closed

Description

@NewPZP

I think the code following is not the right implementation,

https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java

/**

  • Swaps nodes of two given values a and b.

*/
public void swapNodes(int a, int b) {
Node currentNode = head;
Node temp = null;
while (currentNode != null) {
if (currentNode.next.value == a) {
temp = currentNode.next;
}
if (currentNode.next.value == b) {
currentNode.next = temp;
}
currentNode = currentNode.next;
}
}

Activity

  1. zhrgithub commented on Feb 9, 2022

    @zhrgithub
  2. zhrgithub commented on Feb 10, 2022

    @zhrgithub
  3. YashCoder03 commented on Feb 10, 2022

    @YashCoder03

    Yes There is a Problem is swap funtion. They Change the values of Two Nodes Instead of Nodes. The Best Approch the Change the Nodes not values. Because In Real Time project if any node carring big amount of data then it is not good ot change values . it is better to change the Node.

    If You assign this Task to Me Then i can Fix it..

  4. zhrgithub commented on Feb 11, 2022

    @zhrgithub
  5. zhrgithub commented on Feb 11, 2022

    @zhrgithub
  6. github-actions commented on Mar 14, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  7. rajoriaakash commented on Mar 20, 2022

    @rajoriaakash

    Can i try on this issue?

  8. github-actions commented on Apr 20, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  9. github-actions commented on Apr 27, 2022

    @github-actions

    Please reopen this issue once you add more information and updates here. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions