3333 LinkedList updLL1=new LinkedList();
3434 updLL1.formRes(LL1,LL2,LL3,MID);
3535 updLL1.display();
36- updLL1.Size ();
36+ updLL1.size ();
3737
3838 */
3939
40-
41-
4240import java .util .*;
4341import java .lang .*;
4442import java .io .*;
45- class LinkedList {
43+
44+ public class LinkedList {
45+
4646 private class Node {
4747 int data ;
4848 Node next ;
@@ -52,9 +52,16 @@ private class Node{
5252 this .next = null ;
5353 }
5454 }
55- public Node head = null;
56- public Node tail = null;
57- private int size=0;
55+
56+ private Node head ;
57+ private Node tail ;
58+ private int size ;
59+
60+ public LinkedList () {
61+ head = null ;
62+ tail = null ;
63+ size = 0 ;
64+ }
5865
5966 public void addLast (int data ) {
6067 Node newNode = new Node (data );
@@ -92,6 +99,7 @@ public void formLL2(LinkedList LL1) {
9299 current =current .next .next ;
93100 }
94101 }
102+
95103 public void formLL3 (LinkedList LL1 ) {
96104 Node current =LL1 .head .next ;
97105 while (current .next !=null &¤t .next .next !=null ) {
@@ -100,6 +108,7 @@ public void formLL3(LinkedList LL1) {
100108 current =current .next .next ;
101109 }
102110 }
111+
103112 public Node mid () {
104113 Node slow =this .head ;
105114 Node fast =this .head ;
@@ -109,11 +118,13 @@ public Node mid() {
109118 }
110119 return slow ;
111120 }
121+
112122 public Node midValue () {
113123 int sum =this .head .data +this .tail .data ;
114124 Node mid =new Node (sum );
115125 return mid ;
116126 }
127+
117128 public void formRes (LinkedList LL1 ,LinkedList LL2 ,LinkedList LL3 ,Node MID ) {
118129 Node LL1mid =LL1 .mid ();
119130 Node currentLL1 =LL1 .head ;
@@ -135,7 +146,8 @@ else if(currentLL2==null&¤tLL3!=null) {
135146 currentLL1 =currentLL1 .next ;
136147 }
137148 }
138- public void Size() {
149+
150+ public void size () {
139151 System .out .println (this .size );
140152 }
141153 }
0 commit comments