快捷导航

c++数据结构

请问一下大佬们,怎么创建一个不带头结点的单链表?

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

#include#include"malloc.h"usingnamespacestd;structLinkList{intdata;LinkList*next;};voidCreateList_L(LinkList*&L,intn){inti;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;}}intmain(){LinkList*head;CreateList_L(head,5);LinkList*p=head->next;while(p!=NULL){cout
回复

使用道具 举报

可能感兴趣的问答

发新帖
TA的信息
  • 会员所属: 注册会员
  • 认证信息: 邮箱认证手机认证
  • 微信访问
  • 手机APP