Linked List Java Program
Linked List Java Program
{
int data;Node next;
}
////////End of Node Class////
class LinkedList
{
Node Head,Tail;
public void insert(int val)
{
Node New=new Node();
New.data = val;
New.next = null;
if(Head==null)
{
Head = New ; Tail = New;
}
else
{
Node N = Head;
while(N.next != null)
{ N = N.next; }
Tail.next = New; Tail = New;
}
} /// End of insert ()
Output = >
Node=>3 Node=>63 Node=>60 Node 12
Delete Node' data is 60
Node=>3 Node=>63 Node 12
Node=>12 Node=>63 Node 3
Node is Found
Example 2
class Student
{
int rno;String name;int mark;Student next;
}
////////End of Node Class////
class StuLinkedList
{
Student head,tail;
public void insert(int r,int m,String n)
{
Student New=new Student();
New.rno = r;
New.mark=m;
New.name=n;
New.next = null;
if(head==null)
{
head = New ; tail = New;
}
else
{
Student S = head;
while(S.next != null)
{ S = S.next; }
tail.next = New; tail = New;
}
} /// End of insert ()
Output =>
Roll no Name Mark
1 Ya Min 550
2 ChitSu 570
3 SaPal 530
Removed Student is 3
Roll no Name Mark
1 Ya Min 550
2 ChitSu 570
Rno 1 Ya Min is Found.
Student is Found