
Posted by Sapan kumar Dutta on March 30, 204 at 18:55:46:
In Reply to: Re: i want the answer for this question posted by pankaj on December 02, 203 at 09:34:07:
/* REVERSING A LINKED LIST */
/* LINK_REV.C */
#include struct link int i, number; void display(struct link *); /* Reversing the list */ struct link * reverse(struct link *start) while( current1 != NULL ) start = previous; /* Definition of the function */ void display(struct link *node) /* Definition of the function */ void create_list(struct link *node) printf("\n Input the number of nodes you want to create:"); /* CREATE A LINKED LIST */ for (i = 0; i < number ; i++) /* End of function creation */ /* Function main */ void main() node = (struct link *) malloc(sizeof(struct link));
#include
{
int data;
struct link *next;
};
struct link *start, *node, *previous, *current1, *counter;
void create_list(struct link *);
struct link * reverse(struct link *);
{
current1 = start;
previous = NULL ;
{
counter = (struct link *)malloc(sizeof(struct link));
counter = current1->next ;
current1->next = previous ;
previous = current1 ;
current1 = counter;
}
return(start);
}
{
while (node != NULL)
{
printf(" %d", node->data);
node = node->next;
}
}
{
int i;
int number;
scanf("%d", &number);
{
printf("\n Input the node: %d: ", i+1);
scanf("%d", &node->data);
node->next = (struct link* ) malloc(sizeof(struct link));
if( i == number - 1)
node->next = NULL;
else
node = node->next;
}
node->next = NULL;
}
{
struct link *node;
struct link *p;
create_list(node);
printf("\n Original List is as follows:\n");
display(node);
p = ( struct link *)malloc(sizeof(struct link));
p = reverse(node);
printf("\n After reverse operation list is as follows:\n");
display(p);
}
Post a Follow Up: