How to reverse linked list below,thank you! #include <stdlib.h> #include <stdio.h> struct list { int data; struct list *next; }; typedef struct list...

50.1K

Verified Solution

Question

Programming

How to reverse linked list below,thank you!

#include
#include
struct list
{
int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
int main()
{
link ptr,head;
int num,i;

head = ( link ) malloc(sizeof(node));
ptr = head;
printf(\"enter 10 data \n\");
for ( i = 0; i <= 9; i++ )
{
scanf(\"%d\",&num);
ptr->data = num;
ptr->next = ( link ) malloc(sizeof(node));
if ( i == 9 )
ptr->next = NULL;
else
ptr = ptr->next;
}
printf(\"original linked list\n\");
ptr = head;
while ( ptr != NULL )
{
printf(\"data==> %d\n\",ptr->data);
ptr = ptr->next;
}
  
system(\"pause\");
return 0;
}

Answer & Explanation Solved by verified expert
4.3 Ratings (702 Votes)
include include struct listint datastruct list nexttypedef struct list nodetypedef node linklist reverseLinkedList list head if    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students