鱼C论坛

 找回密码
 立即注册
查看: 2813|回复: 1

求助关于数据结构循环链表**p的问题

[复制链接]
发表于 2014-11-8 10:09:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>
typedef int Elemtype;
typedef struct node
{
   Elemtype data;
   struct node *next;
}node;
void ds_init(node*pNode)
{
node *target,*temp;
Elemtype item;
printf("请输入结点的值,输入0结束结束初始化\n");
while(1)
{
  scanf("%d",&item);
  fflush(stdin);
  if(item==0)
   return;
  if(pNode==NULL)
  {
       pNode=(node*)malloc(sizeof(node));
   if(!(pNode))
    exit(0);
   pNode->data=item;
   pNode->next=pNode;
  }
  else
  {
   for(target=pNode;target->next!=pNode;target=target->next);
            temp=(node*)malloc(sizeof(node));
   temp->data=item;
   temp->next=target->next;
   target->next=temp;
  }
}
}
void ds_traverse(node*pNode)
{
node*target;
target=pNode;
printf("**********链表中的元素**********\n");
do
{
  printf("%4d",target->data);
}while((target=target->next)!=pNode);
printf("\n");
}
int main()
{
   void ds_init(node*pNode);
   void ds_traverse(node*pNode);
   node*pNode=NULL;
   ds_init(pNode);
   printf("\n");
   ds_traverse(pNode);
}
我调试好半天都不成功  但是我改成了老师的**p就可以了,请问为什么呀 哪里有问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-11-10 21:54:09 | 显示全部楼层
如果要改变参数的值,传递的参数必须是变量的地址,这一点是不变的
虽然pNode是指针,但它同时也是一个变量,所以必须传递这个指针的地址,也就是传递指向指针的指针(**)以此类推,如果变量是指针的指针(**),那就必须传递指向指针的指针的指针(***)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-18 04:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表