数据结构怎么创建单链表?求答案,问题如下?

2025-03-13 16:11:41
推荐回答(1个)
回答1:

#include
struct LinkNode
{
int value;
LinkNode * next;
};

int main()
{
LinkNode * pHead = NULL;
LinkNode * curPoint = NULL;
int i;

for(i=0;i<5;i++)
{
LinkNode* pLinenode = new LinkNode;
scanf("%d",&pLinenode->value);

if(curPoint != NULL)
{
curPoint->next = pLinenode;
curPoint = pLinenode;
}
else
{
curPoint = pLinenode;
pHead = curPoint;
}

}

curPoint = pHead;
for(i = 0;i< 5;i++)
{
printf("%d\t",curPoint->value);
curPoint= curPoint->next;
}

printf("\n");
return 0;
}