#include <stdio.h>
typedef struct _note{
int data;
struct _note *next;
} Note;
Note* reverseList(Note *head)
{
Note *current, *prev, *next;
current = head;
prev = NULL;
while(current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
head = prev;
return head;
}
Note *insert(Note *head, int data)
{
Note *note = (Note *)malloc(sizeof(Note));
if(note != NULL)
{
note->data = data;
note->next = head;
head = note;
}
return head;
}
void print(Note *head)
{
Note *p = head;
while(p != NULL)
{
printf("%d\n", p->data);
p = p->next;
}
}
// To execute C, please define "int main()"
int main() {
Note *head = NULL;
head = insert(head, 4);
head = insert(head, 5);
head = insert(head, 6);
head = insert(head, 7);
head = insert(head, 8);
print(head);
head = reverseList(head);
print(head);
return 0;
}
typedef struct _note{
int data;
struct _note *next;
} Note;
Note* reverseList(Note *head)
{
Note *current, *prev, *next;
current = head;
prev = NULL;
while(current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
head = prev;
return head;
}
Note *insert(Note *head, int data)
{
Note *note = (Note *)malloc(sizeof(Note));
if(note != NULL)
{
note->data = data;
note->next = head;
head = note;
}
return head;
}
void print(Note *head)
{
Note *p = head;
while(p != NULL)
{
printf("%d\n", p->data);
p = p->next;
}
}
// To execute C, please define "int main()"
int main() {
Note *head = NULL;
head = insert(head, 4);
head = insert(head, 5);
head = insert(head, 6);
head = insert(head, 7);
head = insert(head, 8);
print(head);
head = reverseList(head);
print(head);
return 0;
}