-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Displaying and size of the linked list
- Loading branch information
1 parent
b35d25d
commit 758190f
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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; | ||
if(size==0){ | ||
head=tail=temp; | ||
} | ||
else{ | ||
tail.next=temp; | ||
tail=temp; | ||
} | ||
size++; | ||
} | ||
public int size(){ | ||
return size; | ||
} | ||
public void display(){ | ||
Node temp=head; | ||
while(temp!=null){ | ||
System.out.print(temp.data+" "); | ||
temp=temp.next; | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |