线索链表遇到的一点小问题
来源:互联网 发布:笔记本触摸屏关闭软件 编辑:程序博客网 时间:2024/05/17 01:27
//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)
1 0
- 线索链表遇到的一点小问题
- git遇到的一点小问题
- 二级指针及链表操作中遇到的一点小问题
- 遇到的关于ifstream::eof()的一点小问题
- 本人遇到的关于namespace的一点小问题总结
- 使用CodeIgniter的路径优化遇到的一点小问题
- eclipes发布到tomcat时遇到的一点小问题
- ubuntu 安装Tomcat时遇到的一点小问题
- 关于 VS2010 使用中遇到的一点小问题
- JDBC编程中遇到的一点小问题
- 虚拟机遇到的一点小问题,已经解决了
- 在Mac上开发wp遇到的一点小问题
- cocos中使用Control遇到的一点小问题
- 开发中遇到的一点小问题---写给自己
- 回到顶部 插件 遇到的一点小问题
- 刚开始玩openMP,总结一下遇到的一点小问题。
- elasticsearch遇到的一点问题
- 遇到的小问题
- python中read()、readline()和readlines()的区别
- UVA 10603 FILL 隐式图搜索
- IOS开发---C语言-②交换a、b的值
- OC基础总结
- windows7 安装IE 11,开启仿真模式
- 线索链表遇到的一点小问题
- e盘根目录出现个Msdia80.dll怎么办?
- Phonegap+WebSocket 实现推送功能
- 深入浅出linux-什么是驱动(7)
- JAVA集合类——难得的总结
- POST与GET的区别
- 拖放事件
- 电话拦截
- 斯坦福 机器学习Andrew NG 第一讲 Linear regression with one variable