LinkedList low level implementation [i]
Problem statement: LinkedList low level implementation in java !
- class A1 {
- A1 n;
- int data;
- }
- public class LinkedListLowLevelExe1 {
- A head;
- public static void main(String[] args) {
- A1 head = new A1();
- head.data = 1;
- head.n = null;
- A1 h1 = new A1();
- h1.data = 2;
- h1.n = null;
- head.n = h1;
- A1 h2 = new A1();
- h2.data = 3;
- h2.n = null;
- h1.n = h2;
- A1 h3 = new A1();
- h3.data = 4;
- h3.n = null;
- h2.n = h3;
- A1 h4 = new A1();
- h4.data = 5;
- h4.n = null;
- h3.n = h4;
- System.out.println(head.data); // h.data;
- System.out.println(head.n.data); // h=h.n; h.data;
- System.out.println(head.n.n.data); // h=h.n.n;h.data;
- System.out.println(head.n.n.n.data); // h=h.n.n.n;h.data;
- System.out.println(head.n.n.n.n.data); // h=h.n.n.n.n;h.data;
- }
- }
Output:
1
2
3
4
5
Comments
Post a Comment