zoukankan      html  css  js  c++  java
  • 逆序建立链表

     1 #include<stdio.h>
    2 #include<malloc.h>
    3 struct stu
    4 {
    5 int data ;
    6 struct stu *next ;
    7 };
    8 struct stu *creat(int n)
    9 {
    10 int i;
    11 struct stu *head,*p;
    12 head = (struct stu *)malloc(sizeof(struct stu));
    13 head->next = NULL;
    14 for(i = 1 ; i <= n ;i++)
    15 {
    16 p = (struct stu *)malloc(sizeof(struct stu));
    17 scanf("%d", &p->data);
    18 p->next = head->next;
    19 head->next = p ;
    20 }
    21 return head;
    22 }
    23 void traverse_list(struct stu*head)
    24 {
    25 int i = 1;
    26 struct stu *p;
    27 p = head->next;
    28 while(p!=NULL)
    29 {
    30 if(i != 1)
    31 printf(" ");
    32 printf("%d", p->data);
    33 p = p->next;
    34 i++;
    35 }
    36 printf("\n");
    37 }
    38 int main()
    39 {
    40 int n;
    41 struct stu *head;
    42 scanf("%d", &n);
    43 head = creat(n);
    44 traverse_list(head);
    45 return 0;
    46 }
  • 相关阅读:
    PHP install perl module
    PHP 静态页
    PHP对类的操作
    PHP Mysql操作。
    2020.7.16
    2020.7.19
    2020.7.14
    2020.7.12
    2020.7.17
    2020.7.10
  • 原文地址:https://www.cnblogs.com/shangyu/p/2345688.html
Copyright © 2011-2022 走看看