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

Update LinkedList.java #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Java/DataStructures/LinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public int indexOfLastAppearance(int value) {
}
return position;
}




/* Other Methods */

Expand All @@ -169,7 +170,34 @@ public boolean contains(int value) {
}
return false;
}
/*Mid of a linked list*/
public Node midNode(Node head) {
if (head == null || head.next == null)
return head;

Node slow = head, fast = head;
while (fast.next != null && fast.next.next != null) {
slow = slow.next;
fast = fast.next.next;
}

return slow;
}

public Node midNode2(Node head) {
if (head == null || head.next == null)
return head;

Node slow = head, fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}

return slow;
}


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gursparsh,
The code seems good.

Could you please call the function and add the sample input, output and time and space complexity as well?

If possible, could you add it for all the functions? (Let me know, if this is not convenient, I would take care of it later. )

Also, in the current version of this file, we have lines added due to merge conflicts, Line 1 for example. This seems to have crept in the code, while we were organizing the JAVA folder for the better, for this repository.
Could you please remove such lines from the file, in the next review?

Also, let me know, if you would like to contribute to more issues / repository (Maintainer) in future.

Thanks,
Sukriti

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure! I'll do all the necessary changes and add time complexity for all the functions.
I would be happy to contribute to more issues !

public int size() {
return size;
}
Expand Down