Data structure experiment linked list 3: reverse configuration of the linked list
Data structure experiment linked list 3: reverse configuration of the linked list Time Limit: 1000 MS Memory limit: 65536 K Enter multiple integers in the topic description, and use-1 as the ending mark to create a single-linked table with the leading node in sequence. Then, the data in the single-linked table is reversed, and output the inverted single-chain table data. Enter multiple integers, with-1 as the ending sign. Output the inverted single-chain table data. Sample Input
12 56 4 6 55 15 33 62 -1
Sample output
62 33 15 55 6 4 56 12
The system prompts that arrays are not allowed. Source
Sample program
/*************************************** * *********************************> File Name: data structure experiment linked list 3: reverse configuration of the linked list. c> Author: ttop5> Blog: www.ttop5.net> Mail: 1427154738@qq.com> Created Time: on Wednesday, ******************************** **************************************** /# include
# Include
Struct node {int data; struct node * next;}; // create a chain table in reverse order 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 ;}