The chain list of data structure experiment three: the inverse of the linked list Time limit:1000ms Memory limit:65536k The title describes the input of multiple integers, 1 as the end flag, in order to establish a leading node of the single-linked list, then the data of the single linked list is reversed, and the output of the inverted single-linked list data. Enter multiple integers with 1 as the end flag. Output output inverted single-linked list data. Sample input
12 56 4 6 55 15 33 62-1
Sample output
62 33 15 55 6 4 56 12
Tip do not use arrays. Source
Sample Program
/*************************************************************************> File Name: Data structure experiment chain list three: the inverse of the list .c> Author:ttop5> blog:www.ttop5.net> Mail: [email protected]> Created time:2014 year December 10 Wednesday 20:57 20 seconds ****** /#include <stdio.h> #include <malloc.h >struct node{int data; struct node *next;};/ /reverse Establish linked list struct node *creat () {struct node *head,*p; head= (struct node *) malloc (sizeof (struct node)); head->next=null; p= (struct node *) malloc (sizeof (struct node)); scanf ("%d", &p->data); while (p->data!=-1) {p->next=head->next; head->next=p; p= (struct node *) malloc (sizeof (struct node)); scanf ("%d", &p->data); } return (head);} int main () {struct node *head; Head=creat (); if (head->next!=null) {printf ("%d", head->next->data); head=head->next; } while (Head->next!=null) { printf ("%d", head->next->data); head=head->next; } printf ("\ n"); return 0;}
The chain list of data structure experiment three: the inverse of the linked list