EmbLogic's Blog

program to reverse link list using three pointers

#include
#include
#include
struct node
{
int a;
struct node *next;
};
struct node * create_ll();
void display(struct node *);
void rev(struct node *);
int main()
{
struct node *start ,*temp,*temp1;
int i,n;
start=create_ll();
temp=start;
printf(“enter node\n”);
scanf(“%d”,&n);
for(i = 0; i next=temp1;
temp=temp->next;
}
display(start);
rev(start);
return 0;
}
struct node *create_ll()
{
struct node *start;
start=malloc(sizeof(struct node));
printf(“enter data”);
scanf(“%d”,&start->a);
start->next=NULL;
return start;
}
void display(struct node *start)
{
struct node *temp;
temp=start;
while(temp!=NULL)
{
printf(“data is %d\n”,temp->a);
temp=temp->next;
}
}
void rev(struct node *start)
{
struct node *temp,*temp1;
temp=start;
temp1=start;
while(temp1->next != NULL)
{
temp=temp1->next;
temp1->next=temp1->next->next;
temp->next=start;;
start=temp;
}
printf(“the reversed list is ::::::::\n”);
while(start!=NULL)
{
printf(“data is %d\n”,start->a);
start=start->next;
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>