A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 此生逍遥 中级黑马   /  2014-7-18 23:09  /  1467 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

希望通过一个例子来说明怎样建立一个简单的链表,并输出它。

5 个回复

倒序浏览
  1. #include “stdlib.h”
  2. #include <stdio.h>
  3. #define NULL 0
  4. #define LEN sizeof(struct student)
  5. struct student
  6. {
  7. long num;
  8. float score;
  9. struct student *next;
  10. };
  11.   
  12. int n;
  13. struct student *creat(void)
  14. {
  15.    struct student *head;
  16.    struct student *p1,*p2;
  17.    n=0;
  18.    p1=p2=(struct student *)malloc(LEN);
  19.    scanf(“%ld,%f”,&p1->num,&p1->score);
  20.    head=NULL;
  21.    while(p1->num != 0)
  22.    {
  23.     n=n+1;
  24.     if(n == 1)
  25.      head = p1;
  26.     else
  27.      p2->next = p1;
  28.     p2 = p1;
  29.     p1 = (struct student *)malloc(LEN);
  30.        scanf(“%ld,%f”,&p1->num,&p1->score);
  31.    }
  32.    p2->next = NULL;
  33.    return(head);
  34. }
  35.   
  36. void main()
  37. {
  38.   creat();
  39. }
复制代码
回复 使用道具 举报
回复 使用道具 举报

java不是有现成的LinkedList么?
回复 使用道具 举报
fantacyleo 发表于 2014-7-19 01:16
java不是有现成的LinkedList么?

对啊 ,都用ArrayList,把它忘了
回复 使用道具 举报
这个是什么里面的内容,怎么没见过
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马