View Single Post
  #1 (permalink)  
Old 07-18-2007, 06:49 PM
silvia silvia is offline
Member
 
Join Date: Jul 2007
Posts: 35
silvia is on a distinguished road
Error: cannot find symbol
Please i need help.

Code:
class Node { public Object data; public Node next; public Node() { this.data = null; this.next = null; } public Node(Object a) { this.data = a; this.next = null; } public Node(Object a, Node b) { this.data = a; this.next = b; } }
Code:
public class List { private Node head; private Node tail; public List() { this.head = null; this.tail = null; } public void insertAtFront(Object obj) { if (this.size()==0) { Node n = new Node(obj); this.head = n; this.tail = n; } else { Node n = new Node(obj); n.next = this.head; this.head = n; } } public void insertAtBack(Object obj) { if (this.size()==0) { Node n = new Node(obj); this.head = n; this.tail = n; } else { Node n = new Node(obj); this.tail.next = n; this.tail = n; } } public Object removeFromFront() { if (this.size()==0) { System.out.println("No data to remove."); return null; } else if (this.size()==1) { Object a = this.head.data; this.head = null; this.tail = null; return a; } else { Object a = this.head.data; this.head = this.head.next; return a; } }
Code:
public void insertAtSorted(String s) { if (this.size()==0) { insertAtFront(s); return; } else if (s<=this.head)// stuck on these type of statements { insertAtFront(s); return; } else if (s>=this.tail) // how to make so this works? <---------- { insertAtBack(s); return; } else { Node ntlnode = this.head; while (ntlnode.next <= s) { ntlnode = ntlnode.next; Node blah = new Node(s); blah.next = ntlnode; this.next = blah; } } }
Code:
public Object removeFromBack() { if (this.size()==0) { System.out.println("No data to remove."); return null; } else if (this.size()==1) { Object a = this.tail.data; this.head = null; this.tail = null; return a; } else { Object a = this.tail.data; Node ntlnode = this.head; while (ntlnode.next != this.tail) { ntlnode = ntlnode.next; } this.tail = ntlnode; this.tail.next = null; return a; } } public boolean isEmpty() { return this.head == null; } public void print() { if (this.size()==0) { System.out.println("Empty list!"); return; } Node curr = this.head; while (curr != null) { System.out.println(curr.data.toString()); curr = curr.next; //move forward to the next data item. } System.out.println(); } public int size() { int count = 0; Node curr = this.head; while (curr != null) { count++; curr = curr.next; } return count; } }
The error is:

Code:
List.java:100: operator <= cannot be applied to java.lang.String,java.lang.Object else if (s<=this.head.data) //not sure about this format of object<--------------- ^ List.java:105: operator >= cannot be applied to java.lang.String,java.lang.Object else if (s>=this.tail.data) ^ List.java:113: operator <= cannot be applied to Node,java.lang.String while (ntlnode.next <= s) ^ List.java:118: cannot find symbol symbol : variable next location: class List this.next = blah; ^ 4 errors
Thanks
Reply With Quote
Sponsored Links