-
Notifications
You must be signed in to change notification settings - Fork 20k
I think the method in SinglyLinkedList is not right implementation, #2938
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
Comments
really?
… 2022年2月9日 下午5:44,潘 ***@***.***> 写道:
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 <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;
}
}
—
Reply to this email directly, view it on GitHub <#2938>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJ42SC6PLHVHZISACUK36BTU2IZQVANCNFSM5N46LVTA>.
You are receiving this because you are subscribed to this thread.
|
Why are you think the code following is not the right implementation?
… 2022年2月9日 下午5:44,潘 ***@***.***> 写道:
I think the code following is not the right implementation,
|
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.. |
ok
…---- 回复的原邮件 ----
| 发件人 | Yash ***@***.***> |
| 日期 | 2022年02月11日 01:44 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.******@***.***> |
| 主题 | Re: [TheAlgorithms/Java] I think the method in SinglyLinkedList is not right implementation, (Issue #2938) |
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..
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
done
…---- 回复的原邮件 ----
| 发件人 | Yash ***@***.***> |
| 日期 | 2022年02月11日 01:44 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.******@***.***> |
| 主题 | Re: [TheAlgorithms/Java] I think the method in SinglyLinkedList is not right implementation, (Issue #2938) |
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..
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
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. |
Can i try on this issue? |
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. |
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! |
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
/**
*/
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;
}
}
The text was updated successfully, but these errors were encountered: