I am creating a program that creates a linked list of n length with random ints up to the random limit rLimit. However, I am relatively new to toString() methods and am not sure how to create one that would return the linked list to me. Do you have any suggestions on how to return my linked list in this scenario? Here is what I have so far:
public myLinkedList(int rLimit, int n) {
LinkedList<Integer> list = new LinkedList<Integer>();
//number of nodes
n = 15;
//boundary of random numbers to choose from i.e. 0,1,2...limit-1
rLimit = 10;
Random r = new Random();
for (int i = 0; i < n; i++) {
list.add(r.nextInt(rLimit));
}
}
public String toString() {
return myLinkedList;
}
Aucun commentaire:
Enregistrer un commentaire