How can I fix this error

Write your question here.
On line 11: head = new Node(null);
The IDE gives an error on this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  Put the code you need help with here.
public class FirstList {
	//reference to the head node.
	private Node head;
	private int count;
	
	//LinkedList constructor
	public FirstList() {
		//this is an empty list, so the reference to the head node
		//is set to a new node with no data
		head = new Node(null);
		count = 0;
	}
	@SuppressWarnings("unchecked")
	public void add(Object data)
	//appends the specified element to the end of this list
	{
		Node temp = new Node();
		Node current = head;
		//starting at the head node, crawl to the end of the list
		while(current.getNext() != null) {
			current = current.getNext();
		}
		//the last node's "next" reference set to our new node
		current.setNext(temp);
		count++;
	}
	public Object get() {
		Node current = head.getNext();
		return current.getData();
	}
	public static void main(String[] args) {
		FirstList l = new FirstList();
		l.add(56);
		l.add(25);
	System.out.println(l);	
	}
	

}
Last edited on
closed account (48bpfSEw)
 
private Node head; 


is not a pointer!

try this:
 
private Node *head;


@Necip,

this code looks like Java to me. AFAIK in Java you can't have pointer.
Topic archived. No new replies allowed.