stringinttree.h

来自「这是一个有关哈夫曼编/译码器的课程设计」· C头文件 代码 · 共 55 行

H
55
字号
#ifndef _STRINGTREE_H_
#define _STRINGTREE_H_

#include "BinTree.h"


// CStringIntTreeNode. A node that holds a string and an int
// Since it inherits CBinTreeNode, can it be managed
// by the CBinTree class.
class CStringIntTreeNode : public CBinTreeNode
{
	LPTSTR mString;
	int mInt;
public:
	CStringIntTreeNode(LPCTSTR str,int i);
	~CStringIntTreeNode();

	LPCTSTR GetString() const { return mString; }
	int GetInt() const { return mInt; }
};

// CStringIntTree. A binary tree of CStringIntTreeNode nodes.
class CStringIntTree : public CBinTree
{
protected:
  // Overrides the pure virtual compare function.
  // and compares the strings of the nodes.
  int Compare(CBinTreeNode* p1,CBinTreeNode* p2) const;

  virtual void OnRemoveNode(CBinTreeNode* pNode) { delete (CStringIntTreeNode*)pNode; };
public:
  // Destructor
	~CStringIntTree() { Clear(); };
  
  // Function to directly add CStringIntTreeNode:s to the tree.
  void Add(LPCTSTR str,int i);

  BOOL DeleteByString(LPCTSTR str);
  // Save the contents to a file.
  void Save(LPCTSTR fileName);

  // Load the contents from a file.
  void Load(LPCTSTR fileName);

  // Delete all nodes (not only remove them from the tree)
  void Clear();

  // FindByString. Returns the CStringIntTreeNode matching the
  // given string str or NULL if couldn't be found.
  CStringIntTreeNode* FindByString(LPCTSTR str);
};

#endif // _STRINGTREE_H_

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?