线索链表遇到的一点小问题

//thrbitree.h

#ifndef THRBITREE_H
#define THRBITREE_H
#include <iostream>
using namespace std;
enum flag {child,Thread};
template <class T>
struct ThrNode
{
	T data;
	ThrNode<T> *lchild,*rchild;
	flag ltag,rtag;
};
template <class T>
class InThrBiTree
{
public:
	InThrBiTree();
	~InThrBiTree(){};
	ThrNode<T>*Next(ThrNode<T>*p);
	void InOrder();
private:
	ThrNode<T> *root;
	ThrNode<T> *Creat(ThrNode<T> *bt);
	void ThrBiTree(ThrNode<T> *bt,ThrNode<T> *pre);
};
template <class T>
ThrNode<T>* InThrBiTree<T>::Creat(ThrNode<T> *bt)
{
	char ch;
	cin>>ch;
	if(ch=='#') bt=NULL;
	else {
		bt = new ThrNode<T>;
		bt->data = ch;
		bt->ltag = 0;
		bt->rtag = 0;
		bt->lchild = Creat(bt->lchild);
		bt->rchild = Creat(bt->rchild);
	}
	return bt;
}
template <class T>
void InThrBiTree<T>::ThrBiTree(ThrNode<T> *bt,ThrNode<T> *pre)
{
	if(bt == NULL) return;
	ThrBiTree(bt->lchild,pre);
	if(bt->lchild == NULL) {
		bt->ltag = 1;
		bt->lchild = pre;
	}
	if(bt->rchild == NULL) bt->rtag = 1;
	if(pre->rtag == 1) pre->rchild = bt;
	pre = bt;
	ThrBiTree(bt->rchild,pre);
}
template <class T>
InThrBiTree<T>::InThrBiTree()
{
	root = Creat(root);
	ThrNode<T> *pre = NULL;
	ThrBiTree(root,pre);
}
template <class T>
ThrNode<T>*InThrBiTree<T>::Next(ThrNode<T>*p)
{
	ThrNode<T>*q = NULL;
	if(p->rtag == 1) q = p->rchild;
	else {
		q = p->rchild;
		while(q -> ltag ==1) 
			q = q->lchild;
	}
	return q;
}
template <class T>
void InThrBiTree<T>::InOrder()
{
	ThrNode<T>*p = NULL;
	if(root == NULL) return;
	p = root;
	while(p->ltag == 0)
		p = p->lchild;
	cout<<p->data;
	while(p->rchild != NULL)
	{
		p = Next(p);
		cout<<p->data;
	}
}
#endif

源文件

#include "thrbitree.h"

int main()
{
	cout<<"请输入结点元素:"<<endl;
	InThrBiTree<char> in;
	in.InOrder();
	return 0;
}

--------------------Configuration: 1123——1 - Win32 Debug--------------------
Compiling...
thread.cpp
d:\microsoft visual studio\myprojects\1123——1\thrbitree.h(35) : error C2440: '=' : cannot convert from 'const int' to 'enum flag'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
        d:\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'struct ThrNode<char> *__thiscall InThrBiTree<char>::Creat(struct ThrNode<char> *)'
d:\microsoft visual studio\myprojects\1123——1\thrbitree.h(36) : error C2440: '=' : cannot convert from 'const int' to 'enum flag'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
        d:\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'struct ThrNode<char> *__thiscall InThrBiTree<char>::Creat(struct ThrNode<char> *)'
d:\microsoft visual studio\myprojects\1123——1\thrbitree.h(48) : error C2440: '=' : cannot convert from 'const int' to 'enum flag'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
        d:\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'void __thiscall InThrBiTree<char>::ThrBiTree(struct ThrNode<char> *,struct ThrNode<char> *)'
d:\microsoft visual studio\myprojects\1123——1\thrbitree.h(51) : error C2440: '=' : cannot convert from 'const int' to 'enum flag'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
        d:\microsoft visual studio\vc98\include\xlocale(467) : while compiling class-template member function 'void __thiscall InThrBiTree<char>::ThrBiTree(struct ThrNode<char> *,struct ThrNode<char> *)'
执行 cl.exe 时出错.


1123——1.exe - 1 error(s), 0 warning(s)

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值