Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Add a new item to the end of the list */
- public void addToRear(Data data) {
- Node<Data> newNode = new Node<>(); // 1
- newNode.data = data; // 1
- if (head == null) { // 2
- head = newNode; // 2
- } else {
- Node<Data> current = head; // 3
- while (current.next != null) { // 4
- current = current.next; // 4
- } // 4
- current.next = newNode; // 5
- }
- size++; // 6
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement