#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}list,*lplist;
int main()
{
list list1={1,nullptr};
list list2={2,nullptr};
list list3={3,nullptr};
lplist s=&list1;
list1.next=&list2;
list2.next=&list3;
while(s!=nullptr)
{
printf("%d",s->data);
s=s->next;
}
system("pause");
return 0;
}
另外一种写法:
#include <stdlib.h>
#include <stdio.h>
typedef struct node
{
int data;
struct node *next;
}NODE,*lplist;
void main()
{
NODE node1={1,nullptr};
NODE node2={2,nullptr};
NODE node3={3,nullptr};
lplist p=&node1;
node1.next=&node2;
node2.next=&node3;
while(p!=nullptr)
{
printf("%d->",p->data);
p=p->next;
}
system("pause");
}