hello can you help me please my program will generate error it says can't find symbol Class Node
please help me hoping for your positive responds...

here's the error...

D:\SinglyLinkedList.java:16: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
private Node head;
^
D:\SinglyLinkedList.java:17: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
private Node tail;
^
D:SinglyLinkedList.java:20: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
public Node add(Node n)
^
D:\SinglyLinkedList.java:20: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
public Node add(Node n)
^
D:\SinglyLinkedList.java:41: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
public Node addFirst(Node n)
^
D:\SinglyLinkedList.java:41: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
public Node addFirst(Node n)
^
D:\SinglyLinkedList.java:63: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
public Node getFirst()
^
D:\SinglyLinkedList.java:67: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
public Node getLast()
^
D:\SinglyLinkedList.java:95: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
Node n = new Node();
^
D:\SinglyLinkedList.java:95: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
Node n = new Node();
^
D:\SinglyLinkedList.java:103: cannot find symbol
symbol : class Node
location: class SinglyLinkedList
Node n = list.getFirst();
^
11 errors

Process completed.

public class SinglyLinkedList
	{
		
		private Node head;
		private Node tail;
		private int size=0;
		
		public Node add(Node n)
		{
			
			if(isEmpty())
			{
				head=n;
				tail=n;
				
			}
	
			else
			{
				tail.next=n;
				tail=n;
					
			}			
			
			size ++;
			return n;
		
		}
		public Node addFirst(Node n)
		{
			if(isEmpty())
			{
				head =n;
				tail =n;
				
			}
			
			else
				
			{
				
			  n.next = head;
			  head =n;
				
			}	
			
			return n;	
			
		}
		
		public Node getFirst()
		{
		  return head;
		}
		public Node getLast()
		{
			
			return tail;
		}
		
		public boolean isEmpty()
		{
			
			return head ==  null;
			
		}
		public int size()
		{
			return size;
		}
		
	
	
	public static void main(String[] args)
	{
		
	  SinglyLinkedList list = new SinglyLinkedList();
	  
	  
		
		for(int i=0;i<10;i++)
		{
			Node n = new Node();
			n.value="Miguel" + (i+1);
			list.add(n);
	
			
		}
		
		
		Node n = list.getFirst();
		
		while(n!=null)
		{
			
			System.out.println(n.value);
			n = n.next;	
		}
		
    
	}
	
}

You're referring to a class called Node, but the compiler can't find it. Do you have that class defined somewhere? Maybe in a class called Node.java?

Good to see you're working on linked lists, by the way. Data structures are fun.

You're referring to a class called Node, but the compiler can't find it. Do you have that class defined somewhere? Maybe in a class called Node.java?

Good to see you're working on linked lists, by the way. Data structures are fun.

hello sir thank you for the reply...how can i define the class sir?

hmmm..i think data stracture for me is very complicated but i will try my best to understand this and with the guidance and help with you all,....hoping for your positive responds...

You define Node the same way you defined SinglyLinkedList - by writing the code that spells out what data it contains and what it can do with that data.

class Node {  // The definition of the class Node
String value; // data member
Node next;  // self referencing: referring to itself
}

Self-reference occurs in natural or formal languages when a sentence or formula refers to itself.
http://en.wikipedia.org/wiki/Self-reference

class Node {  // The definition of the class Node
String value; // data member
Node next;  // self referencing: referring to itself
}

Self-reference occurs in natural or formal languages when a sentence or formula refers to itself.
http://en.wikipedia.org/wiki/Self-reference

hello sir tong1,


thank your for the reply and helping...so this is why does my program will not run, i tried it sir and it works..thank you for helping me sir...i will write again for implementing the method..more power to you....

Tong - I wouldn't call "next" a self reference in your Node class. It might, I suppose, in a one-member list, refer to itself but it's generally a reference to another object of the same class.
It's important to keep the distinction straight between Object and Class - if I have your email address, that isn't a self reference, even though we are both objects of the Person class, and the email address is a sort of reference (a pointer, you might say) to such an object.

Thank you , jon, for your quick response and correction. Should we call it "Same Type of Reference" or "Self-Type Reference" rather than self- referencing ?
A linked list contains several Node's objects, which are connected linearly (one by another) via the attribute "next". The "next" is a reference to its next Node' instance. The type of the "next" is also Node: itself Type. Therefore, they are of not only the same type but also itself type (the type as same as itself). The relationship for linked list is one to one.

class Node{
String value; //data member
Node next;    // self-Type reference, Node type reference
}

For the Linkedlist class we may call it as self-referencial class
http://www.cplusplus.com/forum/beginner/3311/

Thank you , jon, for your quick response and correction. Should we call it "Same Type of Reference" or "Self-Type Reference" rather than self- referencing ?
A linked list contains several Node's objects, which are connected linearly (one by another) via the attribute "next". The "next" is a reference to its next Node' instance. The type of the "next" is also Node: itself Type. Therefore, they are of not only the same type but also itself type (the type as same as itself). The relationship for linked list is one to one.

class Node{
String value; //data member
Node next;    // self-Type reference, Node type reference
}

For the Linkedlist class we may call it as self-referencial class
http://www.cplusplus.com/forum/beginner/3311/

hello sir tong1 and jon,

i have question is Node a reserve word? or just an variable?hoping for your positive responds...

I don't know off the top of my head what the best phrase for this is. Auto-typical reference? I'm sure there's an accepted term, but I don't have it in my head.

"Node" is just a class name you have given. It is not a reserved word.

Jemz - if Node were a reserved word, you couldn't use it as the name of a class. Node is a class name, like any other class name that you assign or anyone assigns. There's nothing special about it except that it's the standard name for the thing you just built.

It's definitely not a variable, any more than "String" is a variable. It's a type of object. "next" in your program would be a variable, it's a pointer to a Node. Each Node contains a pointer to another Node, each of those is a variable, containing the address of an instance of Node on the heap.

Edit:
Tong - jinx, buy me a Coke.

I don't know off the top of my head what the best phrase for this is. Auto-typical reference? I'm sure there's an accepted term, but I don't have it in my head.

hello sir,

if you already know the term just let me know sir....can you give me idea how to make method insertAfter(Node n,Node target)?

just step by step sir please, thank you in advance hoping for your positive responds..

Oh, no. I couldn't possibly deprive you of the pleasure of discovering that for yourself.

"Node" is just a class name you have given. It is not a reserved word.

hello sir tong1 and jon,

thank you for the enlighten me..more power to you

Oh, no. I couldn't possibly deprive you of the pleasure of discovering that for yourself.

you mean sir you will not give me an idea?hoping for your positive responds..

Oh, no. I couldn't possibly deprive you of the pleasure of discovering that for yourself.

sir i make the method how can i access this in my main
hoping for your positive responds..

public Node insertAfter(Node n,Node target)
	{
		if(head==null)
		{
			head=n;
			tail=n;
		}
		else
		{
			n.next=target.next;
			target.next=n;
		}
		
		return n;
	}

The code looks good, assuming the purpose is to insert a Node "n" after some given Node "target".

I don't know where you get your reference to "target" from. n is new, you've presumably just made it. target, on the other hand, is already in the list. How you you have a reference to it? (I'll give you a hint: suppose you have a deck of cards, and you're holding the three of spades, and you want to insert the three in the deck after the seven of diamonds. What do you do?)

You access this the same way you access any other method. By calling it.

[reviewing new post]

hello sir i don't know what you mean for me....reviewing new post?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.