Skip to content

Commit c9fb43b

Browse files
authored
Update and rename ListAddnFun to ListAddnFun.java
Updates include: add no-args constructor add whitespace use public class LinkedList use private fields
1 parent 1eb9dcb commit c9fb43b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

DataStructures/Lists/ListAddnFun renamed to DataStructures/Lists/ListAddnFun.java

+20-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
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-
4240
import java.util.*;
4341
import java.lang.*;
4442
import 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&&current.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&&currentLL3!=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

Comments
 (0)