adding an element to the end of a linked list java
class Node {
Object data;
Node next;
Node(Object d,Node n) {
data = d ;
next = n ;
}
public static Node addLast(Node header, Object x) {
// save the reference to the header so we can return it.
Node ret = header;
// check base case, header is null.
if (header == null) {
return new Node(x, null);
}
// loop until we find the end of the list
while ((header.next != null)) {
header = header.next;
}
// set the new node to the Object x, next will be null.
header.next = new Node(x, null);
return ret;
}
}
Also in Java:
- write an infinite loop java
- java 8 iterating and manipulating list
- vertical traversal of binary tree
- numberformatexception
- bukkit java get max players
- how to add an object to a list of objects in java
- java code to save excel data to mysql
- check if string is null or empty java
- how to check how many anagrams a word has in java
- how to create gravity in java
- string to double java exception
- difference between compile and execute in java
- get value textfield java
- Enums injava
- java insert into arraylist
- how to create a button in java
- java swing button on click
- imagesbutton how to set background
- java stack methods
- make a commet in java
- java script removing first three indexes
- hello world java
- how to know when user is done typing android
- java final meaning