level 3
segmentation fault! 一个链表初始化的定义程序。调试的时候显示出错在 if (*pNode == NULL) 百度说指针的问题,本人小白,解决不了,求大神指导,二楼贴程序
2016年03月11日 14点03分
1
level 3
void InitList(node **pNode){ int d, i = 1; node *temp; node *target; printf("请输入结点的值,输入0完成初始化:\n"); while ( 1 ) { scanf("%d",&d); fflush(stdin); if ( 0 == d) { return 0; } if ( *pNode == NULL ) { *pNode = (node *)malloc(sizeof(node)); if (!pNode) { exit(0); } (*pNode)->data = d; // 没有定义头结点,第一个结点就是元素结点! (*pNode)->next = *pNode; } else { for (target = *pNode; target->next != *pNode; target = target->next); temp = (node *)malloc(sizeof(struct node)); if (!temp) { exit(0); } temp->data = d; target->next = temp; temp->next = *pNode; } scanf ("%d",&d); }}
2016年03月11日 14点03分
2
这个用手机发个,乱了
2016年03月11日 15点03分
level 3
void InitList(node **pNode)
{
int d, i = 1;
node *temp;
node *target;
printf("请输入结点的值,输入0完成初始化:\n");
while ( 1 )
{
scanf("%d",&d);
fflush(stdin);
if ( 0 == d)
{
return 0;
}
if ( *pNode == NULL )
{
*pNode = (node *)malloc(sizeof(node));
if (!pNode)
{
exit(0);
}
(*pNode)->data = d;
(*pNode)->next = *pNode;
}
else
{
for (target = *pNode; target->next != *pNode; target = target->next);
temp = (node *)malloc(sizeof(struct node));
if (!temp)
{
exit(0);
}
temp->data = d;
target->next = temp;
temp->next = *pNode;
}
scanf ("%d",&d);
}
}
2016年03月11日 14点03分
3
level 3
int main()
{
node *pHead;
char opp;
int find;
printf("您可以对链表进行以下操作:\n");
printf("1.初始化链表\n\n2.插入结点\n\n3.删除结点\n\n4.返回结点位置\n\n5.遍历结点\n\n0.退出\n\n请选择你的操作?\n\n");
scanf("%c",&opp);
if ('0' != opp)
{
switch(opp)
{
case '1':
InitList(pHead);
printf("\n");
traverse( pHead );
break;
2016年03月11日 14点03分
4
这是引用初始化函数的main函数的前一部分
2016年03月11日 14点03分