adding elements in to the doubly linked list
Posted
by user329820
on Stack Overflow
See other posts from Stack Overflow
or by user329820
Published on 2010-05-30T08:20:52Z
Indexed on
2010/05/30
8:22 UTC
Read the original article
Hit count: 191
java
|linked-list
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)
© Stack Overflow or respective owner