LinkedList low level implementation [v]
Problem statement: LinkedList low level implementation in java !
- class Node3 {
- Node3 next;
- int data;
- Node3(int data) {
- this.data = data;
- }
- }
- public class LinkedListLowLevelExe5 {
- public static void main(String[] args) {
- Node3 head = new Node3(9);
- Node3 h2 = new Node3(2);
- Node3 h3 = new Node3(4);
- Node3 h4 = new Node3(5);
- Node3 h5 = new Node3(8);
- Node3 h6 = new Node3(9);
- // linking the obj reference with the next
- head.next = h2;
- h2.next = h3;
- h3.next = h4;
- h4.next = h5;
- h5.next = h6;
- // h6.next = null;
- print(head);
- }
- static void print(Node3 next) {
- Node3 temp = next;
- while (temp != null) {
- System.out.print(temp.data + "-->");
- temp = temp.next;
- }
- }
- }
Output:
9-->2-->4-->5-->8-->9-->
9-->2-->4-->5-->8-->9-->
Comments
Post a Comment