QUOTE(baavgai @ 10 Oct, 2008 - 06:42 AM)

Well, of course, the problem with circles is finding the end.
I assumed you'd be spinning, the StackOverflowError usually means it got caught in an infinite loop where it was allocating something and eventually ran our of space.
However, the spinning is unrelated to the list
java
public boolean isEmpty() {
if( isEmpty() /* call myself*/ ) {
// you never get here
// more specifically, you never get to the if condition
// it just keeps asking and asking and asking...
ok now i try like this is find now
CODE
public boolean isEmpty()
{
if(header==null)
return true;
return false;
}
but there still problem again here
CODE
public void addFirst(T item)
{
//to insert, create new node with item a value
CNode<T> newNode = new CNode<T>(item);
CNode<T> curr = header;
if(isEmpty())
{ //set the header and the newNode.setNext
header=newNode;
newNode.setNext(header);
}
else
////check if the curr.getNext is not the header
while(curr.getNext()!=header)
{ //what happen to the curr, newNode.setNext and header
curr=curr.getNext();
//post condition: curr is referencing the last node
curr.setNext(newNode);// curr now at newNode
newNode.setNext(header);//
header = newNode;
}
count++;
}
does this method is correct
this is the main method
CODE
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
CList<Integer> aList = new CList<Integer>();
CList<Integer> headerA = new CList<Integer>();
int t;
Integer[] arr = {10, 20, 30, 40, 50, 60, 70, 80, 90};
for(t=0;t<arr.length;t++)
headerA.addFirst(arr[t]);
System.out.println("The list: " + aList.toString());
System.out.println("\n Remove first 3 elements in the list");
//use the for loop to remove the first 3 elements
/* for(int i=0;i<3;i++)
System.out.println("Removing " + headerA..removeFirst());
System.out.println("Current list" + headerA..toString());
System.out.println("\n Clear List\n");
headerA..clear();
System.out.println("Resulting list: "+ headerA..toString());*/
}
}
the output is:
The list:
Lab9.CList@addbf1why it show like this?