请问 代码哪里出错了?
typedef struct _RingNode{
int pos;// 位置
struct _RingNode *next;
}RingNode, *RingNodePtr;
void CreateRing(RingNodePtr pHead, int count)
{
RingNodePtr pCurr = NULL, pPrev = NULL;
int i = 1;
pPrev = pHead;
while(count-- > 0)
{
pCurr = (RingNodePtr)malloc(sizeof(RingNode));
pCurr->pos = i++;
pPrev->next = pCurr;
pPrev = pCurr;
}
pCurr->next = pHead;// 构成环状链表
}
void PrintRing(RingNodePtr pHead)
{
RingNodePtr pCurr;
printf("%d", pHead->pos);
pCurr = pHead->next;
while(pCurr != NULL)
{
if(pCurr->pos == 1)
break;
printf("\n%d", pCurr->pos);
pCurr = pCurr->next;
}
}
int main()
{
int m = 0;
RingNodePtr pHead;
printf("M(out number) = ");
scanf("%d", &m);
CreateRing(pHead, n);
PrintRing(pHead);
system("pause");
return 0;
}输出结果不对,请问哪里有问题啊
路过!!!!!!!!!!!!!!!! void CreateRing(RingNodePtr pHead, int count)改为void CreateRing(RingNodePtr* pHead, int count),要用指针或者引用
你具体想实现什么啊 学习,继续升级中
页:
[1]