亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

c++數據結構

c++數據結構

KY2020 2017-11-08 10:19:06
请问一下大佬们,怎么创建一个不带头结点的单链表?
查看完整描述

1 回答

已采納
?
慕用4063026

TA貢獻195條經驗 獲得超115個贊

#include?<iostream>?
#include"malloc.h"
using?namespace?std;

struct?LinkList
{
?int?data;
?LinkList?*next;
};

void?CreateList_L(LinkList?*&L,int?n)
{?
?int?i;
?LinkList?*p;
?L=(LinkList*)malloc(1);?
?L->next=NULL;??//這句話要加,否則最后會出錯。結尾不為NULL,就沒辦法判斷結束
?for?(i=n;i>0;--i)
?{?
??p=(LinkList*)malloc(1);?
??scanf("%d",&p->data);?
??p->next?=?L->next;
??L->next?=?p;?
?}?

}?

int?main()
{
?LinkList?*head;
?CreateList_L(head,5);
?LinkList?*p=head->next;
?while(p!=NULL)
?{
??cout<<p->data<<"?";
??p=p->next;

?}
?return?0;

}


查看完整回答
1 反對 回復 2017-11-08
  • 1 回答
  • 0 關注
  • 1875 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號