0

I am trying to delete the char from the linked list, but I am getting a null pointer error when I return the object. Can someone please tell me what I am doing wrong?

Here is the code:

public class Answer implements QuestionInterface {
@Override
public SchNode func(SchNode head, char ch){
    SchNode temp=head,temp1;

    while(temp!=null){
        if(temp.ch==ch){
                head=head.nextNode;
        }
        else if(temp.nextNode.ch==ch){
            temp1=temp.nextNode;
            while(temp1.ch==ch){
                temp1=temp1.nextNode;
            }
            temp.nextNode=temp1.nextNode;

        }
        temp=temp.nextNode;

    }
    return head;

    }
}
user812786
  • 4,302
  • 5
  • 38
  • 50

0 Answers0