import [Link].
*;
class Node {
int data;
Node next;
Node prev;
Node (int x){
data = x;
next = null;
prev = null;
}
public static int size(Node a ){
int size = 0;
Node temp = a;
while (temp!=null){
temp = [Link];
size++;
}
return size;
}
public static Node Insertion(Node a, int x ){
Node p = new Node(x);
[Link] = a;
[Link] = null;
if(a!= null) [Link] = p;
// a = p;
return p;
}
public static Node insertionAtLast(Node a , int x){
Node last = new Node(x);
[Link] = null;
if (a == null){
a = last;
[Link] = null;
return last;
}
Node temp = a;
while([Link]!=null){
temp =[Link];
}
[Link] = last;
[Link] = temp;
return a;
public static Node insertionAfterK(Node a , int x , int k){
Node add = new Node(x);
Node temp = a;
Node previous = null;
while(temp!= null && [Link] != k){
temp = [Link];
}
[Link] = add;
[Link] = [Link];
[Link] = [Link];
return a;
}
public static void Deletion(Node a ){
Node temp =a ;
}
public static void main(String[] args) {
Node a = new Node (5);
Node b = new Node (10);
Node c = new Node (15);
Node d = new Node (20);
[Link] = b;
[Link] = a;
[Link] = c;
[Link] = b;
[Link] = d;
[Link] = c;
int size = size(a);
a = Insertion(a, 0);
a = insertionAtLast(a, 25);
a = insertionAfterK(a, 30, 25 );
Node temp = a ;
while (temp!=null){
[Link]([Link] + " ");
temp = [Link];
}
}
}
/////tenth of october
/* package whatever; // don't place package name! */
import [Link].*;
import [Link].*;
import [Link].*;
/* Name of the class has to be "Main" only if the class is public. */
class Node {
int data;
Node next;
Node prev;
Node (int x){
data = x;
next = null;
prev = null;
}
public static Node returnNode(Node head){
if (head == null){
return null;
}
Node slow = head;
Node fast = head;
while(fast!=null && [Link]!=null){
slow = [Link];
fast = [Link];
}
return slow;
}
public static Node reverseLL(Node head){
if (head == null || [Link] == null ){
return head;
}
Node prev = null;
Node next = null;
Node temp = head;
while(temp!= null){
next = [Link];
[Link] = prev;
prev = temp;
temp = next;
}
return prev;
}
public static Node recurseReverse(Node head){
if (head == null || [Link] == null){
return head;
}
Node ans = recurseReverse([Link]);
[Link] = head;
[Link] = null;
return ans;
}
Node sortedMerge(Node head1, Node head2) {
Node temp1 = head1;
Node temp2 = head2;
Node res = new Node (-1);
Node ans = res;
while (temp1!= null && temp2 !=null){
if ([Link]<=[Link]){
[Link] = temp1;
temp1=[Link];
}else{
[Link] = temp2;
temp2 = [Link];
}
res = [Link];
if (temp1== null){
[Link] = temp2;
}
if(temp2 == null){
[Link] = temp1;
}
}
return [Link];
}
public static void main (String[] args) throws [Link]
{
Node a = new Node (5);
Node b = new Node (10);
Node c = new Node (15);
Node d = new Node (20);
[Link] = b;
[Link] = a;
[Link] = c;
[Link] = b;
[Link] = d;
[Link] = c;
Node temp = returnNode(a);
Node ans = reverseLL(a);
while (temp!=null){
[Link]([Link] + " ");
temp = [Link];
}
}