Title Description:
Enter a list of all the elements of the linked list after the list is reversed.
(Hint: Be sure to use a linked list)
Input:
The input may contain multiple test samples, and the input ends with EOF.
For each test case, the first behavior of the input is an integer n (0<=n<=1000): Represents the number of linked lists that will be entered.
The second line of input contains n integers t (0<=t<=1000000): Represents the linked list element.
Output:
corresponding to each test case,
This outputs the inverted element of the list, and outputs null if there are no elements.
Sample Input:
5
1 2 3 4 5
0
Sample output:
5 4 3 2 1
NULL
#include <stdio.h> #include <malloc.h> struct node {int data;
struct node *next;
};
void Main () {int n,i; while (scanf ("%d", &n)!=eof) {struct node *head,*p; Head=null; Do not allocate memory to head for (i=0;i<n;i++) {
int k;
p= (struct node *) malloc (sizeof (struct node));
scanf ("%d", &p->data);
p->next=head;
head=p; } for (;p!=null;p=p->next ) { if (p->next==null) {
printf ("%d\n", p->data); } Else
printf ("%d", p->data); } if (p==head) { printf ("null\
n ");
} }}