首页 > 其他 > 详细

动态链表

时间:2017-08-15 20:27:24      阅读:159      评论:0      收藏:0      [点我收藏+]
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <string>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <malloc.h>
 8 using namespace std;
 9 const int N = 1000;
10 
11 struct weapon{
12     int price;
13     int atk;
14     struct weapon * next;
15 };
16 
17 struct weapon *create(){
18     struct weapon * head;
19     struct weapon * p1, *p2;
20     int n=0;
21     p1=p2=(struct weapon*)malloc(sizeof(struct weapon));
22     scanf("%d %d",&p1->price,&p1->atk);
23     head=NULL;
24     while(p1->price!=0){
25         n++;
26         if(n==1) head=p1;
27         else p2->next=p1;
28         p2=p1;
29         p1=(struct weapon*)malloc(sizeof(struct weapon));
30         scanf("%d %d",&p1->price,&p1->atk);
31     }
32     p2->next=NULL;
33     return (head);
34 }
35 
36 int main()
37 {
38     struct weapon *p;
39     p=create();
40     printf("%d %d",p->price,p->atk);
41     return 0;
42 }

 

动态链表

原文:http://www.cnblogs.com/shixinzei/p/7366996.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!