c语言中单循环链表建立,怎么用c++建立单循环链表?

#include

#include

#include

typedef struct node

{

int date;

struct node *next;

}slnode,*Linklist;

void creat_list(Linklist H)//创建链表,由于实参传值使L指向了一个空节点从而成为头节点指针

{

Linklist p, p1;

int n;

cout<

cin>>n;

H->date=n;

cout<

p1 = H;//使p1具有了空间

for(int i=0;i

{

p=(Linklist)malloc(sizeof(slnode));

p->next = NULL;

cin>>p->date;

H->next = p;

H=p;//L指向了最后节点的数据域

};

H=p1;//使尾指针指向了最后节点的数据域

}

void display_list(Linklist H)//输出链表

{

cout<

Linklist p;

p = H-> next;

for(int i=0;idate;i++)

{

cout<date;

cout << ' ';cout<

p = p -> next;

}

}

void main()

{

slnode a;//a是空结构变量

Linklist p;//p是指针

p = &a;//p指向了一个空节点

creat_list(p);//传的是结构变量的地址

display_list(p);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值