zbdn 2021-02-28 17:31 采纳率: 64.3%
浏览 90
已结题

出现C4430问题,怎么解决?

在头文件的59、70行出现该问题,若改为bool,void,int类型,越改问题越多,应该怎么改?头文件理应不会有顺序错误或者重复包含的问题

//LinkedBinTree.h
#include"stdafx.h"

#include<iostream>
using namespace std;

template<class T>
class LinkedNode
{
	template<class T>
	friend class LinkedBinTree;
public:
	LinkedNode()
	{
		m_pLeftChild=m_pRightChild=NULL;
	}
	LinkedNode(const T &x)
	{
		m_pLeftChild=m_pRightChild=NULL;
		m_data=x;
	}
private:
	T m_data;
	LinkedNode<T>*m_pLeftChild,*m_pRightChild;
};

template<class T>
class LinkedBinTree
{
public:
	LinkedBinTree();
	~LinkedBinTree();
	bool IsEmpty();
	LinkedNode<T>*CreateRoot(const T&x);
	LinkedNode<T>*GetRoot();
	bool GetNodeValue(LinkedNode<T>*pNode, T &x);
	 LinkedNode<T>*InsertLeftChild(LinkedNode<T>*pNode,const T&x);
     LinkedNode<T>*InsertRightChild(LinkedNode<T>*pNode,const T&x);
	bool GetLeftChild(LinkedNode<T>*pNode);
	bool GetRightChild(LinkedNode<T>*pNode);
	void InOrderTraverse(LinkedNode<T>*pNode);
private:
	LinkedNode<T>*m_pRoot;};

template<class T>
LinkedBinTree<T>::LinkedBinTree()
{
	m_pRoot=NULL;}

template<class T>
int LinkedBinTree<T>::InsertLeftChild(LinkedNode<T>*pNode,const T&x)
{
	LinkedNode<T>*pNewNode;
	if(pNode==NULL)
		return NULL;
	pNewNode=new LinkedNode<T>(x);
	if(pNewNode==NULL)
		return NULL;
	pNode->m_pLeftChild=pNewNode;
	return pNewNode;}

template<class T>
LinkedBinTree<T>::InsertRightChild(LinkedNode<T>*pNode,const T&x)
{
	LinkedNode<T>*pNewNode;
	if(pNode==NULL)
		return NULL;
	pNewNode=new LinkedNode<T>(x);
	if(pNewNode==NULL)
		return NULL;
	pNode->m_pRightChild=pNewNode;
	return pNewNode;}


template<class T>
LinkedNode<T>*LinkedBinTree<T>::CreateRoot(const T&x)
{
	if(m_pRoot!=NULL)
		m_pRoot->m_data=x;
	else
		m_pRoot=new LinkedNode<T>(x);
	return m_pRoot;}

template<class T>
LinkedNode<T>*LinkedBinTree<T>::GetRoot()
{
	return m_proot;}

template<class T>
bool LinkedBinTree<T>::GetNodeValue(LinkedNode<T>*pNode,T&x)
{
	if(pNode==NULL)
		return false;
	x=pNode->m_data;
	return true;}

template<class T>
bool GetLeftChild(LinkedNode<T>*pNode)
{ if(pNode==NULL)
  return NULL;
return pNode->m_pLeftChild;
}

template<class T>
bool GetRightChild(LinkedNode<T>*pNode)
{
	if(pNode==NULL)
		return NULL;
	return pNode->m_pRightChild;}




template<class T>
void InsertBST(LinkedBinTree<T>&btree,T K)
{
	LinkedNode<T>*pNode=NULL,*pChild=NULL;
	T x;
	if(btree.IsEmpty())
	{
		btree.CreateRoot(K);
		return ;}
	pNode=btree.GetRoot();
	while(pNode)
	{
		btree.GetNodeValue(pNode,x);
		if(K==x)
			return;
		if(K<x)
		{
			if((pChild=btree.GetLeftChild(pNode))!=NULL)
				pNode=pChild;
			else
			{
				btree.InsertLeftChild(pNode,K);
				return;
			}
		}
		else
		{
			if((pChild=btree.GetRightChild(pNode))!=NULL)
				pNode=pChild;
			else
			{
				btree.InsertRightChild(pNode,K);
				return;
			}
		}
	}
}

template<class T>
void CreateBST(T R[],int nSize,LinkedBinTree<T>&btree)
{
	int nI;
	for(nI=1;nI<nSize;nI++)
		InsertBST(btree,R[nI]);
}

template<class T>
LinkedNode<T>*SearchInsertBST(LinkedBinTree<T>&btree,T K)
{
	LinkedNode<T>*pNode=NULL,*pChild=NULL;
	T x;
	if(btree.IsEmpty())
	{
		btree.CreateRoot(K);
		return NULL;
	}
	pNode=btree.GetRoot();
	while(pNode)
	{
		btree.GetNodeValue(pNode,x);
		if(K==x)
			return pNode;
		if(K<x)
		{
			if((pChild=btree.GetLeftChild(pNode))!=NULL)
				pNode=pChild;
			else
			{
				btree.InsertLeftChild(pNode,K);
				return NULL;
			}
		}
		else
		{
			if((pChild=btree.GetRightChild(pNode))!=NULL)
				pNode=pChild;
			else
			{
				btree.InsertRightChild(pNode,K);
				return NULL;
			}
		}
	}
	return NULL;
}

template<class T>
void LinkedBinTree<T>::InOrderTraverse(LinkedNode<T>*pNode)
{
	if(pNode==NULL)
		return;
	InOrderTraverse(pNode->m_pLeftChild);
	InOrderTraverse(pNode->m_pRightChild);
}


//A.cpp
#include "stdafx.h"
#include"LinkedBinTree.h"

#include<iostream>
using namespace std;

int main()
{ int nR[]={0,43,56,37,28,17,39,22};
  int nSize=sizeof(nR)/sizeof(nR[0]);
  int nK=39,nX=0;
  LinkedBinTree<int>btree;
  LinkedNode<int>*pNode=NULL;
  CreateBST(nR,nSize,btree);
  btree.InOrderTraverse(pNode);
  cout<<endl;
  pNode=SearchInsertBST(btree,nK);
  if(pNode!=NULL)
  {
	  btree.GetNodeValue(pNode,nX);
	  cout<<nX<<"查找成功"<<endl;
  }
  else
	  cout<<"查找失败"<<endl;
	return 0;
}
  • 写回答

2条回答 默认 最新

  • 全栈探索者 2021-02-28 17:39
    关注

    定义的是int类型,return的不是 

    评论

报告相同问题?

悬赏问题

  • ¥20 SQL server表计算问题
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出