Skip to content

NullPointer Exception is handled. #4142

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

Merged
merged 8 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Changes were done and checked Junit testcases
  • Loading branch information
Akshith121 committed Apr 15, 2023
commit cee806d446f9cb9896a3a92d5800bb5cf4e319b0
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,17 @@ public Node reverseList(Node node) {
Node prev = null;
Node curr = node;

while (curr != null) {
while (curr != null && curr.next != null) {
Node next=curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
//when curr.next==null, the current element is left without pointing it to its prev,so
if(curr != null){
curr.next = prev;
prev=curr;
}
//prev will be pointing to the last element in the Linkedlist, it will be the new head of the reversed linkedlist
return prev;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ void reverseListTest(){
int i=20; //This is for the comparison of values of nodes of the reversed linkedlist
//Checking whether the reverseList() method performed its task
while(temp!=null && i>0){
assertEquals(temp.value,i);
temp=temp.next;
i--;
assertEquals(i,temp.value);
temp=temp.next;
i--;
}
}

Expand Down