LinkedList low level implementation [iv]
Problem statement: LinkedList low level implementation in java !
- class Node2 {
- Node2 next;
- int data;
- Node2(int data) {
- this.data = data;
- }
- }
- public class LinkedListLowLevelExe4 {
- public static void main(String[] args) {
- Node2 head = new Node2(4);
- Node2 h2 = new Node2(5);
- Node2 h3 = new Node2(6);
- Node2 h4 = new Node2(8);
- head.next = h2;
- h2.next = h3;
- h3.next = h4;
- h4.next = null;
- print(head);
- }
- public static void print(Node2 next) {
- Node2 temp = next;
- while (temp != null) {
- System.out.print(temp.data + "-->");
- temp = temp.next;
- }
- }
- }
Output:
4-->5-->6-->8-->
4-->5-->6-->8-->
Comments
Post a Comment