The chain list of data structure experiment three: the inverse of the linked list

Source: Internet
Author: User

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

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.