双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

大家好,我有个很棘手的问题,帮忙看下,能编译通过但是不能运行

mr_caoke mr_caoke 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


LinkList.h

typedef struct LNode
{
int nData;
LNode *pNext;
}LinkList;

bool InitLinkList(LinkList *L, const int arrData[], const int nLength);
bool DisplayLinkList(const LinkList *L);




LinkList.cpp

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

bool InitLinkList(LinkList *L, const int arrData[], const int nLength)
{

L = (LinkList *)malloc(sizeof(LinkList));
L->pNext = NULL;
LNode *pNode = NULL;

for (int i = 0; i < nLength; i++)
{
pNode = (LNode *)malloc(sizeof(LNode));

if (NULL == pNode)
{
printf("InitList Failed!");
return false;
}

pNode->nData = arrData[i];
pNode->pNext = L->pNext;
L->pNext = pNode;
}

return true;
}


bool DisplayLinkList(const LinkList *L)
{

if (NULL == L->pNext)
{
return false;
}

LNode *pNode = L->pNext;


while (NULL != pNode->pNext) //就到这里就过不去了
{
cout << 1 << endl;

cout << pNode->nData << ",";
pNode = pNode->pNext;
}

cout << pNode->nData << endl;
return true;

}






main.cpp

#include "LinkList.h"

int main(int argc, char* argv[])
{
LinkList List;
int Array[10] = {2, 3, 5, 8, 9, 11, 34, 101, 66, 90};

if( !InitLinkList(&List, Array, sizeof(Array)/sizeof(int)) )
{
return -1;
}

if (!DisplayLinkList(&List))
{
return -1;
}

return 0;
}



这个是一个简单的链表程序,可以编译通过,但是无法运行,问题出在DisplayLinkList这个函数,
哪位大侠帮忙解释一下为啥,谢谢了






...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
mr_caoke
C++ 语言 65,214 成员 250,514 内容