-1

It's showing some kind to error at head "Cannot resolve symbol 'head' ".

import java.util.LinkedList;

public class reversellusingiteration {
    static Node head;

    static class Node{
        int data;
        Node next;
        Node(int d) {
            this.data = d;
            this.next = null;
        }
    }

    Node reverse(Node node){
        Node curr=node;
        Node prev=null;
        while(curr!=null){
            Node temp=curr.next;
            curr.next=prev;
            prev=curr;
            curr=temp;
        }
        return prev;
    }
    public static void main(String[] args) {
        LinkedList list=new LinkedList();
        list.head =new Node(90); //here is the problem
        list.head.next=new Node(78);
    }
}

Please someone help me with this

Jens
  • 67,715
  • 15
  • 98
  • 113
  • 1
    PLease take care of java naming conventions. Class names should start with upper case character – Jens Jul 06 '23 at 16:33

1 Answers1

0

Your class reversellusingiteration has two problems. The static Node head; should not be static. And it is not named LinkedList. So you need to change

LinkedList list=new LinkedList();

to

reversellusingiteration list = new reversellusingiteration();
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249