Creation, Insertion , Deletion, Searching and Traversing Algorithms for Single linked list ?

https://www.computersprofessor.com/2017/04/creation-insertion-deletion-searching.html
Single linked list creation:
class node
{
int
x ;
node
next;
}
int no ;
node
head, null, end ,p, q ;
System
.out. println (“enter how many nodes do u want”);
no=Integer.parseInt(br.
readLine());
while(no>=1)
{
p=
new node( );
System.
out .println (“enter data”);
p.
n= Integer.parseInt(br. readLine());
p.
next=null;
if(head==null)
{
head=p;
end=p;
q=p;
}
else
{
q.
next =p;
q=p;
end=p;
}
no
- - ;
}
Insertion: Insertion can be done at 3 places
1. Insertion at beginning
2. Insertion at ending
3. Insertion at user choice
Insertion at beginning :
Before insertion :
After Insertion :
p= new node ( )
System.out.println(“enter data “);
p.n= Integer.parseInt(br. readLine());
p. next= null;
p. next= head;
head=p;
Insertion at user choice :
Before insertion :
After insertion:
p= new node ( );
System. Out. Println(“enter
data”);
p.n = Integer.parseInt(br. readLine());
p. next=null;
System . out. println(“enter
position”);
int pos= Integer.parseInt(br. readLine());
q=head;
r= head.next;
while(pos -1>1)
{
q=q.next;
r=r.
next;
pos
- - ;
}
q.
next=p;
p.next=r;
Insertion at ending:
before insertion :
After insertion :
p= new node ( );
System.out.println(“enter data”);
p.n= Integer.parseInt(br. readLine());
p.next=null;
q= head;
while(q.next!=null)
{
q=q.next;
}
q.next=p;
end=p;
Deletion :Deletion can be done at 3 places.
1. Deletion At Beginning
2. Deletion at ending
3. Deletion at user choice
Deletion at beginning :
Before deletion :
After deletion :
p=head;
Head=head.next;
p. next=null;
Deletion at ending user choice:
Before deletion :
After deletion :
System.out.println(“enter position
do u want to delete”);
pos= Integer.parseInt(br. readLine());
q=head;
r=head.next;
while(pos.1>1)
{
q=q.next;
r=r.next;
pos
- -;
}
q.next=r.next;
r.next=null;
Deletion at ending :
Before deletion :
After deletion :
q= head;
r=head.next;
while(r.next!=null)
{
q=q.next;
r=r.next;
}
end=q;
q.next=null;
Traversing :
Traversing means visit or display
the node exactly once.
p= head;
while (p!=null)
{
System.out.println(p.n);
p=p. next;
}
Searching :
int
found=0;
p=
head;
System.out.println(“enter
element to search”);
int
ele= Integer.parseInt(br. readLine());
while(p!=
null)
{
if(p.n==ele)
{
found=1;
break;
}
p=p.next;
}
if(found==1)
{
System.out.println(“element
found”);
}
else
{
System.out.
ptintln(“element not found”);
}
break;