Data structure experiment linked list 3: reverse configuration of the linked list

Source: Internet
Author: User

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 ;}
  
 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.