单向链表

Posted 松手丶明晃晃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单向链表相关的知识,希望对你有一定的参考价值。

 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 }

 

以上是关于单向链表的主要内容,如果未能解决你的问题,请参考以下文章