I am trying to create a linked list of a fixed amount of nodes, it has to contain a random int in each note that does not go over a specific range represented by m. n is the size of the linked list. This is what I tried to do, but I am getting a lot of errors with the data types.
import java.util.Random;
import java.util.Scanner;
public class Garcia_Daniela_Lab2 {
public class iNode{
public int item;
public iNode next;
}
public void iNode(int i, iNode n){
int item = i;
iNode next = n;
}
public void iNode(int i){
int item =i;
iNode next = null;
}
public iNode list(int n, int m){
Random r = new Random();
iNode l = null; //check that n is greater that 0
iNode head = r.nextInt(m);
for(int i=1; i<n;){
l.next=r.nextInt(m);
}
return head;
}
Aucun commentaire:
Enregistrer un commentaire