二叉树建立时候指针调用的内存为空

-1
#include<iostream>
#include<stdio.h>
using namespace std;

#define FALSE 0
#define TRUE 1

typedef struct Date
{
	char coord;
	float Wins;
}Date;

typedef struct Csnode
{
	Date chess;
	struct Csnode* firstchild;
	struct Csnode* nextsibling;
}Csnode, * Tree;

void IntChessTree(Tree& T, int i)
{
	Tree p;
	Tree r;

	float b = 0;

	if (i > 1)
	{
		p = (Tree)malloc(sizeof(Csnode));

		b = b + 1;
		p->chess.Wins = b;

		//p->firstchild = NULL;
		//p->nextsibling = NULL;
		T->firstchild = p;
		while (i > 1)
		{
			r = (Csnode*)malloc(sizeof(Csnode));

			b = b + 1;
			r->chess.Wins = b;

			//r->firstchild = NULL;
			//r->nextsibling = NULL;
			p->nextsibling = r;
			IntChessTree(p, i - 1);
			p = p->nextsibling;
		}
	}
}

在 r->chess.Wins = b; 处报错:

0x00E8192C 处(位于 井字棋.exe 中)引发的异常: 0xC0000005: 写入位置 0x00000004 时发生访问冲突。

*****我这是把蒙特卡洛树用线索二叉树实现的

ava
思逐风云上

2019-11-4

0

你的代码并不完整,无法判定问题在哪。

ava
慢羊羊

2019-11-7

技术讨论社区