adding elements in to the doubly linked list
- by user329820
Hi
this is my code for main class and doubly linked class and node class but when I run the program ,in the concole will show this"datastructureproject.DoublyLinkedList@19ee1ac" instead of the random numbers .please help me thanks!
main class:
public class Main {
public static int getRandomNumber(double min, double max) {
Random random = new Random();
return (int) (random.nextDouble() * (max - min) + min);
}
public static void main(String[] args) {
int j;
int i = 0;
i = getRandomNumber(10, 10000);
DoublyLinkedList listOne = new DoublyLinkedList();
for (j = 0; j <= i / 2; j++) {
listOne.add(getRandomNumber(10, 10000));
}
System.out.println(listOne);
}
}
doubly linked list class:
public class DoublyLinkedList {
private Node head ;
private Node tail;
private long size = 0;
public DoublyLinkedList() {
head= new Node(0, null, null);
tail = new Node(0, head, null);
}
public void add(int i){
head.setValue(i);
Node newNode = new Node();
head.setNext(newNode);
newNode.setPrev(head);
newNode = head;
}
}
and the node class is like the class that you have seen before (Node prev,Node next,int value)