/* Reverse the singly linked list */
#include<stdio.h>
#include<conio.h>
#include<process.h>
struct node
{
int info;
struct node *link;
}*start=NULL;
void main()
{
struct node *temp,*q,*p,*t;
int n,i,x;
clrscr();
printf("\n Enter How many number:-");
scanf("%d",&n);
for(i=0;i<n;i++)
{
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
getch();
exit(0);
}
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
q=start;
while(q->link!=NULL)
{
q=q->link;
}
q->link=temp;
}
}
t=NULL;
for(i=0;i<n;i++)
{
q=start;
while(q->link!=t)
{
q=q->link;
}
t=q;
printf("\n %d",q->info);
}
getch();
}
/* OUTPUT
Enter How many number:-5
Enter number:-1
Enter number:-2
Enter number:-3
Enter number:-4
Enter number:-5
5
4
3
2
1
#include<stdio.h>
#include<conio.h>
#include<process.h>
struct node
{
int info;
struct node *link;
}*start=NULL;
void main()
{
struct node *temp,*q,*p,*t;
int n,i,x;
clrscr();
printf("\n Enter How many number:-");
scanf("%d",&n);
for(i=0;i<n;i++)
{
temp=(struct node*)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\n Insufficient memory");
getch();
exit(0);
}
printf("\n Enter number:-");
scanf("%d",&x);
temp->info=x;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
q=start;
while(q->link!=NULL)
{
q=q->link;
}
q->link=temp;
}
}
t=NULL;
for(i=0;i<n;i++)
{
q=start;
while(q->link!=t)
{
q=q->link;
}
t=q;
printf("\n %d",q->info);
}
getch();
}
/* OUTPUT
Enter How many number:-5
Enter number:-1
Enter number:-2
Enter number:-3
Enter number:-4
Enter number:-5
5
4
3
2
1