亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? binarytree.h

?? C++編成數據結構與程序設計方法 D.S.Malk編著
?? H
字號:
//Header File Binary Search Tree
#ifndef H_binaryTree
#define H_binaryTree

#include <iostream>

using namespace std;

    //Definition of the Node
template <class elemType>
struct nodeType
{
    elemType info;
    nodeType<elemType> *lLink;
    nodeType<elemType> *rLink;
};
	
    //Definition of the class
template <class elemType>
class binaryTreeType
{
public:
    const binaryTreeType<elemType>& operator=
                 (const binaryTreeType<elemType>&); 
      //Overload the assignment operator.

    bool isEmpty() const;
      //Function to determine whether the binary tree is empty.
      //Postcondition: Returns true if the binary tree is empty;
      //               otherwise, returns false.

    void inorderTraversal() const;
      //Function to do an inorder traversal of the binary tree.
      //Postcondition: Nodes are printed in inorder sequence.

    void preorderTraversal() const;
      //Function to do a preorder traversal of the binary tree.
      //Postcondition: Nodes are printed in preorder sequence.

    void postorderTraversal() const;
      //Function to do a postorder traversal of the binary tree.
      //Postcondition: Nodes are printed in postorder sequence.

    void inorderTraversal(void (*visit) (elemType&)) const;
      //Function to do an inorder traversal of the binary tree.
      //The parameter visit, which is a function, specifies
      //the action to be taken at each node.
      //Postcondition: The action specified by the function 
      //               visit is applied to each node of the 
      //               binary tree.

    int treeHeight() const;
      //Function to determine the height of a binary tree.
      //Postcondition: Returns the height of the binary tree.

    int treeNodeCount() const;
      //Function to determine the number of nodes in a 
      //binary tree.
      //Postcondition: Returns the number of nodes in the 
      //               binary tree.

    int treeLeavesCount() const;
      //Function to determine the number of leaves in a 
      //binary tree.
      //Postcondition: Returns the number of leaves in the 
      //               binary tree.

    void destroyTree();
      //Function to destroy the binary tree.
      //Postcondition: Memory space occupied by each node 
      //               is deallocated.
      //               root = NULL;

    virtual bool search(const elemType& searchItem) const = 0;
      //Function to determine if searchItem is in the binary 
      //tree.
      //Postcondition: Returns true if searchItem is found in 
      //               the binary tree; otherwise, returns 
      //               false.

    virtual void insert(const elemType& insertItem) = 0;
      //Function to insert insertItem in the binary tree.
      //Postcondition: If there is no node in the binary tree
      //               that has the same info as insertItem, a
      //               node with the info insertItem is created
      //               and inserted in the binary search tree.

    virtual void deleteNode(const elemType& deleteItem) = 0;
      //Function to delete deleteItem from the binary tree 
      //Postcondition: If a node with the same info as 
      //               deleteItem is found, it is deleted from
      //               the binary tree.
      //               If the binary tree is empty or 
      //               deleteItem is not in the binary tree, 
      //               an appropriate message is printed.

    binaryTreeType(const binaryTreeType<elemType>& otherTree); 
      //Copy constructor

    binaryTreeType();   
      //Default constructor

    ~binaryTreeType();   
      //Destructor

protected:
    nodeType<elemType>  *root;

private:
    void copyTree(nodeType<elemType>* &copiedTreeRoot,
                  nodeType<elemType>* otherTreeRoot);
      //Makes a copy of the binary tree to which 
      //otherTreeRoot points. 
      //Postcondition: The pointer copiedTreeRoot points to
      //               the root of the copied binary tree.

    void destroy(nodeType<elemType>* &p);
      //Function to destroy the binary tree to which p points. 
      //Postcondition: Memory space occupied by each node, in 
      //               the binary tree to which p points, is 
      //               deallocated.
      //               p = NULL;

    void inorder(nodeType<elemType> *p) const;
      //Function to do an inorder traversal of the binary
      //tree to which p points.  
      //Postcondition: Nodes of the binary tree, to which p
      //               points, are printed in inorder sequence.

    void preorder(nodeType<elemType> *p) const;
      //Function to do a preorder traversal of the binary
      //tree to which p points.  
      //Postcondition: Nodes of the binary tree, to which p
      //               points, are printed in preorder 
      //               sequence.

    void postorder(nodeType<elemType> *p) const;
      //Function to do a postorder traversal of the binary
      //tree to which p points.  
      //Postcondition: Nodes of the binary tree, to which p
      //               points, are printed in postorder 
      //               sequence.

    void inorder(nodeType<elemType> *p, 
                 void (*visit) (elemType&)) const;
      //Function to do an inorder traversal of the binary tree
      //starting at the node specified by the parameter p. 
      //The parameter visit, which is a function, specifies the
      //action to be taken at each node.
      //Postcondition: The action specified by the function visit
      //               is applied to each node of the binary tree
      //               to which p points.

    int height(nodeType<elemType> *p) const;
      //Function to determine the height of the binary tree
      //to which p points. 
      //Postcondition: Height of the binary tree to which 
      //               p points is returned.

    int max(int x, int y) const;
      //Function to determine the larger of x and y.
      //Postcondition: Returns the larger of x and y.

    int nodeCount(nodeType<elemType> *p) const;
      //Function to determine the number of nodes in 
      //the binary tree to which p points. 
      //Postcondition: The number of nodes in the binary 
      //               tree to which p points is returned.

    int leavesCount(nodeType<elemType> *p) const;
      //Function to determine the number of leaves in  
      //the binary tree to which p points 
      //Postcondition: The number of leaves in the binary 
      //               tree to which p points is returned.
};

	//Definition of member functions

template <class elemType>
binaryTreeType<elemType>::binaryTreeType()
{
    root = NULL;
}

template <class elemType>
bool binaryTreeType<elemType>::isEmpty() const
{
    return (root == NULL);
}

template <class elemType>
void binaryTreeType<elemType>::inorderTraversal() const
{
    inorder(root);
}

template <class elemType>
void binaryTreeType<elemType>::preorderTraversal() const
{
    preorder(root);
}

template <class elemType>
void binaryTreeType<elemType>::postorderTraversal() const
{
    postorder(root);
}

template <class elemType>
int binaryTreeType<elemType>::treeHeight() const
{
    return height(root);
}

template <class elemType>
int binaryTreeType<elemType>::treeNodeCount() const
{
    return nodeCount(root);
}

template <class elemType>
int binaryTreeType<elemType>::treeLeavesCount() const
{
    return leavesCount(root);
}

template <class elemType>
void  binaryTreeType<elemType>::copyTree
                       (nodeType<elemType>* &copiedTreeRoot,
                        nodeType<elemType>* otherTreeRoot)
{
    if (otherTreeRoot == NULL)
        copiedTreeRoot = NULL;
    else
    {
        copiedTreeRoot = new nodeType<elemType>;
        copiedTreeRoot->info = otherTreeRoot->info;
        copyTree(copiedTreeRoot->lLink, otherTreeRoot->lLink);
        copyTree(copiedTreeRoot->rLink, otherTreeRoot->rLink);
    }
} //end copyTree

template <class elemType>
void binaryTreeType<elemType>::inorder
                              (nodeType<elemType> *p) const
{
    if (p != NULL)
    {
        inorder(p->lLink);
        cout << p->info << " ";
        inorder(p->rLink);
    }
}

template <class elemType>
void binaryTreeType<elemType>::preorder
                              (nodeType<elemType> *p) const
{
    if (p != NULL)
    {
        cout << p->info << " ";
        preorder(p->lLink);
        preorder(p->rLink);
    }
}

template <class elemType>
void binaryTreeType<elemType>::postorder
                              (nodeType<elemType> *p) const
{
    if (p != NULL)
    {
        postorder(p->lLink);
        postorder(p->rLink);
        cout << p->info << " ";
    }		
}

   //Overload the assignment operator
template <class elemType>
const binaryTreeType<elemType>& binaryTreeType<elemType>::
        operator=(const binaryTreeType<elemType>& otherTree)
{ 
    if (this != &otherTree) //avoid self-copy
    {
        if (root != NULL)   //if the binary tree is not empty,
                            //destroy the binary tree
            destroy(root);

        if (otherTree.root == NULL) //otherTree is empty
            root = NULL;
        else
            copyTree(root, otherTree.root);
    }//end else

    return *this; 
}

template <class elemType>
void  binaryTreeType<elemType>::destroy(nodeType<elemType>* &p)
{
    if (p != NULL)
    {
        destroy(p->lLink);
        destroy(p->rLink);
        delete p;
        p = NULL;
    }
}

template <class elemType>
void  binaryTreeType<elemType>::destroyTree()
{
    destroy(root);
}

	//copy constructor
template <class elemType>
binaryTreeType<elemType>::binaryTreeType
                (const binaryTreeType<elemType>& otherTree)
{
    if (otherTree.root == NULL) //otherTree is empty
        root = NULL;
    else
        copyTree(root, otherTree.root);
}

    //Destructor
template <class elemType>
binaryTreeType<elemType>::~binaryTreeType()
{
    destroy(root);
}

template<class elemType>
int binaryTreeType<elemType>::height
                             (nodeType<elemType> *p) const
{
    if (p == NULL)
        return 0;
    else
        return 1 + max(height(p->lLink), height(p->rLink));
}

template <class elemType>
int binaryTreeType<elemType>::max(int x, int y) const
{
    if (x >= y)
        return x;
    else
        return y;
}

template <class elemType>
int binaryTreeType<elemType>::nodeCount(nodeType<elemType> *p) const
{
    cout << "Write the definition of the function nodeCount."
         << endl;

    return 0;
}

template <class elemType>
int binaryTreeType<elemType>::leavesCount(nodeType<elemType> *p) const
{
    cout << "Write the definition of the function leavesCount."
         << endl;

    return 0;
}

template <class elemType>
void binaryTreeType<elemType>::inorderTraversal
                        (void (*visit) (elemType& item)) const
{ 
    inorder(root, *visit);
}

template <class elemType>
void binaryTreeType<elemType>::inorder(nodeType<elemType>* p,
                         void (*visit) (elemType& item)) const
{
    if (p != NULL)
    {
        inorder(p->lLink, *visit);
        (*visit)(p->info);
        inorder(p->rLink, *visit);
    }
}

#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人午夜在线免费| 岛国av在线一区| 国产aⅴ综合色| 91美女片黄在线| 在线观看亚洲精品视频| 91蜜桃在线观看| 日韩一区二区三区四区五区六区| 欧美日韩国产乱码电影| 国产欧美1区2区3区| 亚洲欧美一区二区三区国产精品| 久久综合九色综合97婷婷| 欧美精品一区二区三区一线天视频 | 国产日韩av一区| 美女网站色91| 色综合久久中文字幕综合网| 91免费视频网| 精品国产精品网麻豆系列 | 亚洲欧美日韩一区二区三区在线观看 | 不卡视频一二三四| 日韩免费高清av| 亚洲一区在线观看免费观看电影高清| 久久精品国产一区二区| 日本乱人伦一区| 亚洲视频一区在线| 99久久精品久久久久久清纯| 欧美一区二区三区视频| 1000精品久久久久久久久| 国产乱码精品一区二区三区av | 69精品人人人人| 亚洲v中文字幕| 欧美少妇xxx| 日韩精品一二三| 欧美人牲a欧美精品| 一个色在线综合| 色婷婷av一区二区三区软件| 国产拍揄自揄精品视频麻豆| 久久精品国产亚洲5555| 在线不卡中文字幕播放| 亚洲午夜三级在线| 欧美最猛性xxxxx直播| 日本一二三四高清不卡| 久久成人免费日本黄色| 精品国产乱码久久久久久久久| 亚洲最新视频在线观看| 欧美在线free| 免费在线成人网| 精品久久一区二区三区| 国内成人免费视频| 国产无人区一区二区三区| 天堂资源在线中文精品| 欧美va亚洲va| a亚洲天堂av| 亚洲欧美日韩电影| 97se亚洲国产综合自在线| 亚洲一卡二卡三卡四卡无卡久久| 欧美日韩一区二区电影| 老司机精品视频导航| 国产精品国产馆在线真实露脸 | 日本中文字幕一区二区视频| 国产嫩草影院久久久久| 欧美视频中文字幕| 国产一区二区三区在线观看免费 | 亚洲一区二区三区精品在线| 一本一本大道香蕉久在线精品 | 免费在线看成人av| 亚洲午夜在线视频| 亚洲欧美激情视频在线观看一区二区三区 | 欧美国产精品专区| 国产精品高清亚洲| 亚洲三级电影网站| 香蕉加勒比综合久久| 五月婷婷色综合| 狠狠色狠狠色综合系列| 麻豆国产欧美日韩综合精品二区| 日本一区中文字幕| 亚洲国产日韩精品| 青娱乐精品视频| 国产一区欧美二区| 9l国产精品久久久久麻豆| 成a人片国产精品| 欧美日韩精品专区| 精品三级av在线| 国产精品久久久久久久久动漫| 亚洲三级电影网站| 亚洲香肠在线观看| 紧缚捆绑精品一区二区| 成人精品一区二区三区四区| 欧美在线观看一二区| 日本高清视频一区二区| 欧美网站一区二区| 久久久久久久久久久99999| 国产精品你懂的| 九九**精品视频免费播放| 国产精品18久久久| 色狠狠综合天天综合综合| 日韩一级大片在线观看| 亚洲欧美国产77777| 国产一区二三区| 91精品久久久久久久久99蜜臂| 国产亚洲精品精华液| 亚洲国产一区视频| 国产suv精品一区二区三区| 欧美三区在线视频| 国产精品久久久久影院色老大| 捆绑变态av一区二区三区| 欧美天堂一区二区三区| 亚洲国产一区二区在线播放| 色菇凉天天综合网| 伊人色综合久久天天| 99久久er热在这里只有精品15| 久久久精品欧美丰满| 国产一区二区精品久久99| 国产亚洲精品资源在线26u| 国产成人精品免费看| 精品福利一二区| 成人丝袜视频网| 中文字幕一区二区三区不卡在线 | 欧美96一区二区免费视频| 欧美高清视频一二三区| 韩国成人精品a∨在线观看| 日本一区二区免费在线| 91女神在线视频| 美女性感视频久久| 亚洲欧洲制服丝袜| 精品国产免费一区二区三区香蕉| 国产成人免费视频网站| 日本中文字幕一区二区有限公司| 中文字幕第一区第二区| 在线免费视频一区二区| 国内精品免费**视频| 亚洲国产成人tv| 国产日韩欧美精品在线| 欧美一a一片一级一片| 麻豆精品一区二区综合av| 亚洲人精品午夜| 日韩午夜在线影院| 日本韩国一区二区| 成人动漫在线一区| 久久精品72免费观看| 亚洲综合网站在线观看| 久久婷婷成人综合色| 欧美精品自拍偷拍动漫精品| av电影在线观看一区| 国产一区999| 国产一区二区在线观看视频| 麻豆精品国产91久久久久久| 亚洲女同ⅹxx女同tv| 欧美xxxxx裸体时装秀| 欧美日韩亚洲不卡| 91黄色免费版| 在线观看一区二区视频| 成人av网站免费| 99re视频精品| 欧美午夜免费电影| 欧美这里有精品| 日韩欧美成人午夜| 国产亚洲精久久久久久| 久久九九国产精品| 精品免费一区二区三区| 日韩欧美色电影| 91 com成人网| 2021久久国产精品不只是精品| 欧美日韩精品一区二区三区四区 | 337p亚洲精品色噜噜噜| 国产亚洲午夜高清国产拍精品| 国产欧美日韩三区| 亚洲理论在线观看| 国内成人自拍视频| 91久久人澡人人添人人爽欧美| 日韩一区二区三区视频| 久久久亚洲精华液精华液精华液| 成人免费在线视频观看| 日韩精品视频网| 3atv在线一区二区三区| 成人欧美一区二区三区1314| 偷拍与自拍一区| 国产精品亚洲人在线观看| 欧美精品在线观看播放| 中文字幕在线观看一区二区| 亚洲福利国产精品| 99re免费视频精品全部| 欧美成人精品福利| 日韩av中文字幕一区二区| 91精品一区二区三区在线观看| 亚洲欧洲国产日韩| 91视频观看视频| 亚洲日本成人在线观看| 国产精品一二三四区| 国产亚洲欧洲997久久综合| 国内精品免费在线观看| 欧美一区二区三区成人| 日韩av一级电影| 成人综合婷婷国产精品久久 | 91免费观看国产| 一区二区三区四区不卡视频| 色欧美片视频在线观看| 亚洲区小说区图片区qvod| 91成人免费电影| 亚洲高清不卡在线| 久久免费看少妇高潮|