2013年11月2日星期六

Who will help me look wrong ? I'm new to this .

I want to create a chain table , sir into several random numbers, and then put the chain table of random numbers written inside, but always wrong , what have I gone wrong ?
public class Class
{


public Node head;
public Class (T [] value) / / the array of values ​​written into a single linked list
{

Node rear = this.head;
for (int i = 0; i {

rear.next = new Node (value [i], null) ;/ /?
rear = rear.next;

}

}

public T get (int i) / / returns a single list of values
{
if (i> 0)
{
Node p = this.head. next;
for (int j = 0; p! = null && j p = p.next;
if (p! = null)
return p.data;
}
return null;
}
public String toString ()
{
String str = "(";
Node p = this.head. next;
while (p! = null)
{
str + = p.data.toString ();
if (p.next! = null)
{
str + = ",";
p = p.next;
}
}
return str + ")";
}

public static void main (String [] args)
{

Integer value [] = new Integer [10];
for (int i = 0; i <10; i + +)
{
value [i] = (int) (Math.random () * 1000);
}

Class a = new Class (value); / /?

System.out.println (a.toString ());
}

}
------ Solution ----------------------------------- ---------
how sent to non-technical areas of ?
------ For reference only -------------------------------------- -
is not running or can not get the results you want ? There are two types of single chain , the lead single linked list of nodes and a single linked list head pointer , if you can run , you understand these two types of single-chain to know is where the wrong.

没有评论:

发表评论