2
2
Write a program to find the length of the linked list using recursion
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node*next;
};
if(p==NULL)
return 0;
else
return 1+lengthOflinkedlist(p->next);
int main()
struct node*q;
struct node*r;
struct node*s;
struct node*t;
p->data=18;
r->data=49;
s->data=59;
t->data=62;
t->next=NULL;
return 0;
Output:
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node*next;
};
int i=1;
while(p!=NULL)
{
printf("Entered number = %d\n",p->data);
p=p->next;
while(curr!=NULL&&temp!=NULL)
curr->next=temp->next;
free(temp);
curr=curr->next;
if(curr!=NULL)
temp=curr->next;
return p;
int main()
struct node*q;
struct node*r;
struct node*s;
struct node*t;
q->data=23;
r->data=49;
s->data=59;
t->data=62;
t->next=NULL;
display(p);
p=alt_delete(p);
display(p);
return 0;
Output:
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node*next;
};
struct node*a=p;
struct node*b=p;
while(b!=NULL&& b->next!=NULL)
a=a->next;
b=b->next->next;
while(curr!=NULL)
tem=curr->next;
curr->next=prev;
prev=curr;
curr=tem;
b=p;
while(prev!=NULL)
if(b->data!=prev->data)
return 0;
b=b->next;
prev=prev->next;
return 1;
}
int main()
struct node*q;
struct node*r;
struct node*s;
struct node*t;
p->data=18;
q->data=23;
r->data=49;
s->data=23;
t->data=18;
t->next=NULL;
if(checkPlaindrome(p))
else
Output:
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node*next;
};
int i=1;
while(p!=NULL)
p=p->next;
while(curr!=NULL)
tem=curr->next;
curr->next=prev;
prev=curr;
curr=tem;
p=prev;
return p;
int main()
struct node*q;
struct node*r;
struct node*s;
struct node*t;
p->data=18;
q->data=23;
r->data=49;
s->data=59;
t->data=62;
t->next=NULL;
display(p);
p=reverse(p);
display(p);
return 0;
Output: