Skip to content

Commit

Permalink
adding last element in the linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
suhanigupta23 authored Sep 8, 2024
1 parent 1ee67e4 commit bd74eb2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions add_last_to_linked_list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.*;
import java.util.*;

public class Main{
public static class Node{
int data;
Node next;
}
public static class LinkedList{
Node head;
Node tail;
int size;

void addList(int val){
Node temp=new Node();
temp.data=val;
temp.next=null;
size++;
if(size==0){
head=tail=temp;
}
else{
tail.next=temp;
tail=temp;
}
}
}
}

0 comments on commit bd74eb2

Please sign in to comment.