码迷,mamicode.com
首页 > 其他好文 > 详细

单向链表

时间:2018-01-30 16:44:33      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:pac   post   include   sizeof   while   单向链表   c++   nod   size   

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct node{
 4     int num;
 5     struct node *next;
 6 };
 7 int main(){
 8     struct node *p,*p1,*head;
 9         head=p=(struct node *)malloc(sizeof(struct node));
10             while(scanf("%d",&p->num)&&p->num!=0){
11                 p1=p;
12                 p=(struct node *)malloc(sizeof(struct node));
13                 p1->next=p;
14             }
15                 p->next=NULL;
16                 p=head;
17             printf("数据如下:\n");
18         while(p->next!=NULL){
19             printf("%d ",p->num);
20             p=p->next;
21         }
22     printf("\n");
23 return 0;
24 }

 

单向链表

标签:pac   post   include   sizeof   while   单向链表   c++   nod   size   

原文地址:https://www.cnblogs.com/wlgclining/p/8384272.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!