单向链表

 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 }

 

posted @ 2018-01-30 11:32  松手丶明晃晃  阅读(112)  评论(0编辑  收藏  举报