Put the code you need help with here.
package Lists;
//Let's look at another possible implementation of the singly linked list.
//Note that this implementation is a singly linked list with a dummy head.
//We use nested class for the implementation.
publicclass SimpleList {
private Node head = new Node(null, null); // dummy head
privateint size;
publicvoid addFirst(Object object) {
head.next = new Node(object, head.next);
size++;
}
publicvoid addLast(Object object) {
// here I don't need a tail reference
Node temp = head;
while(temp.next != null)
temp = temp.next;
temp.next = new Node(object, null);
size++;
}
public Object first() {
if (size == 0) thrownew IllegalStateException("the list is empty");
return head.next.object;
}
public boolean isEmpty() {
return (size == 0);
}
public Object removeFirst() {
if (size == 0) thrownew IllegalStateException("the list is empty");
Object object = head.next.object;
head.next = head.next.next;
size--;
return object;
}
publicint size() {
return size;
}
privatestaticclass Node {
// the Node class is defined within the SimpleList class
Object object;
Node next;
Node(Object object, Node next) {
this.object = object;
this.next = next;
}
}
publicstaticvoid main(String[] args) {
SimpleList simplelist = new SimpleList();
simplelist.addFirst(new Integer(56));
System.out.println(simplelist);
}
}
//Important: Inserting a node into or deleting a node from a linked list follows a strict sequence of steps.
//Changing the order of the steps in the sequence would lead to incorrect results.
It is correct, if you use the object name as a parameter of the System.out.println(...) function, you will see something like you had as an output - the name of the class of which the object is an instance, @ character, and the unsigned hexadecimal representation of the hash code of the object.
What did you want to see instead of this?