Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6dfcd43

Browse files
committed
LinkedList.java modified
1 parent 4ff1033 commit 6dfcd43

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

‎DataStructure/LinkedList.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ public void addFirst(int data){
2626
}
2727

2828
public void addLast(int data){
29-
Node newNode = new Node(data);
3029
if(size == 0){
3130
addFirst(data);
3231
}
3332
else {
33+
Node newNode = new Node(data);
3434
tail.next = newNode;
3535
tail = newNode;
3636
size++;
3737
}
3838
}
3939

4040
public void add(int k, int data){
41-
if(k == 0){
41+
if(k == 0){
4242
addFirst(data);
4343
}else{
4444
Node temp1 = node(k-1);
@@ -109,6 +109,13 @@ public int getElement(int k){
109109
return temp.data;
110110
}
111111

112+
// Output
113+
// [30, 10, 20]
114+
// 10
115+
// [30, 20]
116+
// 2
117+
//20
118+
112119
public static void main(String[] args) {
113120
LinkedList list = new LinkedList();
114121
list.addLast(10);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /