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

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

Closed
NewPZP opened this issue Feb 9, 2022 · 9 comments
Closed

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

NewPZP opened this issue Feb 9, 2022 · 9 comments
Labels

Comments

@NewPZP
Copy link

NewPZP commented Feb 9, 2022

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

@zhrgithub
Copy link

zhrgithub commented Feb 9, 2022 via email

@zhrgithub
Copy link

zhrgithub commented Feb 10, 2022 via email

@YashCoder03
Copy link

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..

@zhrgithub
Copy link

zhrgithub commented Feb 11, 2022 via email

@zhrgithub
Copy link

zhrgithub commented Feb 11, 2022 via email

@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Mar 14, 2022
@rajoriaakash
Copy link

Can i try on this issue?

@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Apr 20, 2022
@github-actions
Copy link

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
Labels
Projects
None yet
Development

No branches or pull requests

4 participants