public class SNode
{
int data;
SNode next;
public SNode (int data, SNode f)
{
this.data=data;
next = f;
}
public SNode(int data)
{
data=data;
}
}
public class SLL
{
SNode head;
public SLL()
{
head = null;
public boolean isEmpty()
{
return head == null;
public void delAll()
{
head = null;
public void display()
{
if(!isEmpty())
{
SNode p = head;
while (p!=null)
{
System.out.println(p.data);
}
p=p.next;
}
}
public int length()
{
int c= 0;
SNode p = head;
while (p!=null)
{
c++;
}
p=p.next;
return c;
}
public boolean search(int d)
{
if(!isEmpty())
{
SNode p = head;
while (p!=null) {
if (p.data == d)
{
return true;
}
p=p.next;
}
}
return false;
}
public int getFirst ()
{
if(!isEmpty())
{
return head.data;
}
else
return -9999;
}
public int getLast ()
{
if(!isEmpty())
{
SNode p = head;
while (p.next!=null)
{
p=p.next;
}
return p.data;
}
return -9999;
}
public void addFirst (int data)
{
SNode z= new SNode(data);
z.next=head;
head=z;
}
public void addLast (int data)
{
SNode g = new SNode(data);
if(!isEmpty())
{
SNode p = head;
while(p.next!=null)
{
p=p.next;
}
head =g;
}
}
public int addIn (int d, int after)
{
SNode z= new SNode(d);
SNode p = head;
while (p!=null)
{
if(p.data==after)
{
break;
}
else
p=p.next;
}
if (p!=null)
{
z.next=p.next;
p.next=z;
}
else
addLast(d);
return d;
}
public void delFirst()
{
head=head.next;
public void delLast()
{
SNode p =head;
if (!isEmpty())
{
if(p.next!=null)
{
p =head;
}
while (p.next.next!=null)
{
p=p.next;
}
p.next=null;
}
else
head = null;
}