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

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

?? mapavl.template.cpp

?? The existed tree implementation
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// file: MapAVL.template// Template implementation file for the MapAVL class/*--------------------------------------------------------------------------*//*                                                                          *//*  This class implements a map using AVL trees                             *//*                                                                          *//*- Modification History ---------------------------------------------------*//*  When:       Who:                    Comments:                           *//*                                                                          *//*  18-Mar-92   Christopher G. Healey   Initial implementation              *//*  07-Jan-93   Christopher G. Healey   Converted to work as a dictionary   *//*  04-Jul-93   Christopher G. Healey   Converted to C++                    *//*  28-Jul-98   Felix Chang             Change the interface to             *//*                                        follow the other Map template     *//*                                        class examples.                   *//*  20-Jun-01   Paul Carter             Changed so that this class is       */
/*                                      derived from MapAbstract base class */
/*--------------------------------------------------------------------------*/template <class Key, class Value>MapAVL<Key,Value>::MapAVL( )// Default constructor
// POST: An empty MapAVL is created{   root = NULL;}template <class Key, class Value>MapAVL<Key,Value>::MapAVL( const MapAVL<Key,Value>& someMapAVL )// Copy constructor
// POST: A new MapAVL is created containing the same elements as originalMapAVL{   copy( someMapAVL );}template <class Key, class Value>MapAVL<Key,Value>::~MapAVL()// Destructor
// POST: The MapAVL object is destroyed{   eraseTree( root );}template <class Key, class Value>MapAVL<Key,Value>& MapAVL<Key,Value>::operator=( const MapAVL<Key,Value>& someMapAVL )// Member operator function
// POST:  The contents of 'otherMapAVL' are copied into the current MapAVL{   if ( &someMapAVL != this )   {      eraseTree( root );      copy( someMapAVL );   }   return *this;}template <class Key, class Value>bool MapAVL<Key,Value>::empty( const Key& key ) const// Pre: key has been initialized
// Post: if the key is not in the map true is returned; otherwise
// false is returned{   MapAVLNode<Key,Value>* ptr = root;   while(ptr != NULL)   {     if (ptr->key == key)     {        return false;     }     if (ptr->key < key)     {        ptr = ptr->right;     }     else     {        ptr = ptr->left;     }   }

   return true;}template <class Key, class Value>void MapAVL<Key,Value>::erase( const Key& key )// Pre: key has been initialized
// Post: if key is in the map it has been removed; otherwise
// map is not changed{   bool shorter;                      // Tree shorter flag   root = eraseNode( root, key, shorter );}template <class Key, class Value>MapAVLNode<Key,Value>* MapAVL<Key,Value>::eraseNode( MapAVLNode<Key,Value>* tree, const Key& key, bool& shorter )// Private helper function that erases a key from a subtree.
// PRE:   key has been initialized
// POST:  If key is already in the tree, then it is deleted (and the new root returned)
//        otherwise map is not changed
//        Also, shorter will be set according to whether the tree has become shorter or not.{   //  ******************* Case 1 *******************   //  First possibility, root is NULL, so this is the bottom of the tree.   //  Node with given key certainly doesn't exist; so return NULL.   if ( tree == NULL )   {      shorter = false;            // Height of tree unchanged      return NULL;   }   //  ******************* Case 2 *******************   //  Second possibility, key equal to root's key, so found node. Node to   //  delete has two children, find it's predecessor, copy predecessor's   //  info into the root node, then delete the predecessor   if ( tree->key == key && tree->left && tree->right )   {      MapAVLNode<Key,Value>* child;    // Child of root node      // Find the predecessor of root.      child = tree->left;      while( child->right != NULL ) {         child = child->right;      }      tree->key = child->key;      tree->value = child->value;      tree->left = eraseNode( tree->left, child->key, shorter );      //  If the subtree shrunk in size, we must check to see if we are now      //  unbalanced. There are three possible cases:      //      //  1. currently LH, left subtree shrunk, so we are now EQ, and we      //     report that this tree shrunk in height      //  2. currently EQ, left subtree shrunk, so we are now RH, and we      //     report that this tree did not shrink in height      //  3. currently RH, left subtree shrunk, so we are out of balance,      //     and must perform a rotation to bring ourselves back into balance      //      //  If the subtree didn't shrink in size, then we didn't shrink either      if ( shorter )        {          switch( tree->factor )          // Determine current balancing factor          {            case LH:                      // Now, left and right same height               shorter = true;               tree->factor = EQ;               return tree;            case EQ:                      // Now, right 1 higher than left               shorter = false;               tree->factor = RH;               return tree;            case RH:                      // Now, we must rebalance                shorter = (tree->factor != EQ);               return rightBalance( tree );           }           shorter = false;    // If subtree isn't shorter, then this tree isn't shorter either.           return tree;        }   }   //  ******************* Case 3 *******************   //  Third possibility, key equal to root's key, so found node. Node to   //  delete has at most one child, simply have the parent point around   //  it to it's child subtree, or NULL if no subtrees exist   if ( tree->key == key )   {      shorter = true;   // Subtree is shorter      if ( tree->left )   // Root has left subtree?      {        MapAVLNode<Key,Value>* result = tree->left;        delete tree;        // The following code is necessary as of Release 3.4.0 of g++        // The code        //        //     count--;        //        // does not work because members inherited from the base class        // are not recognized in standard C++.  They either have to be        // fully qualified (as below) or you can instead say        //        //     this->count--;        //        MapAbstract<Key,Value>::count--;        return result;      }      if ( tree->right )   // Root has right subtree?      {        MapAVLNode<Key,Value>* result = tree->right;        delete tree;        MapAbstract<Key,Value>::count--;        return result;      }      // No left nor right subtree      delete tree;      MapAbstract<Key,Value>::count--;      return NULL;   }   //  ******************* Case 4 *******************   //  Fourth possibility, key is less than root's key, so search the left   //  subtree recursively   if ( tree->key > key )   {      tree->left = eraseNode( tree->left, key, shorter );      //  If the subtree shrunk in size, we must check to see if we are now      //  unbalanced.  There are three possible cases:      //      //  1. currently LH, left subtree shrunk, so we are now EQ, and we      //     report that this tree shrunk in height      //  2. currently EQ, left subtree shrunk, so we are now RH, and we      //     report that this tree did not shrink in height      //  3. currently RH, left subtree shrunk, so we are out of balance,      //     and must perform a rotation to bring ourselves back into balance      //      //  If the subtree didn't shrink in size, then we didn't shrink, either      if ( shorter )      {         switch( tree->factor )         // Determine current balancing factor         {          case LH:                      // Now, left and right same height             shorter = true;             tree->factor = EQ;             return tree;          case EQ:                      // Now, right 1 higher than left             shorter = false;             tree->factor = RH;             return tree;          case RH:                      // Now, we must rebalance              shorter = (tree->factor != EQ);             return rightBalance( tree );         }      }      // If subtree isn't shorter, then this tree isn't shorter either.      // So just return the tree.      return tree;   }   //  ******************* Case 5 *******************   //  Fifth (final) possibility, key is greater than root's key, so search the   //  right subtree recursively   tree->right = eraseNode( tree->right, key, shorter );   //  If the subtree shrunk in size, we must check to see if we are now   //  unbalanced, As mentioned in class, there are three possible cases:   //   //  1. currently RH, right subtree shrunk, so we are now EQ, and we   //     report that this tree shrunk in height   //  2. currently EQ, right subtree shrunk, so we are now LH, and we   //     report that this tree did not shrink in height   //  3. currently LH, right subtree shrunk, so we are out of balance,   //     and must perform a rotation to bring ourselves back into balance   //   //  If the subtree didn't shrink in size, then we didn't shrink, either   if ( shorter )   {      switch( tree->factor )            // Determine current balancing factor      {          case RH:                      // Now, left and right same height             shorter = true;             tree->factor = EQ;             return tree;          case EQ:                      // Now, left 1 higher than right             shorter = false;             tree->factor = LH;             return tree;          case LH:                      // Now, we must rebalance ourselves             shorter = (tree->factor != EQ );             return leftBalance( tree );      }   }   // If subtree isn't shorter, then this tree isn't shorter either.   // So just return the tree.   return tree;}template <class Key, class Value>Value& MapAVL<Key,Value>::operator[]( const Key& key )// Pre: key has been initialized
// Post: if key is in the map, reference to value corresponding to key 
//       has been returned; otherwise key has been added to map with 
//       corresponding default value
// Exception: if not enough memory to add key, map_full has been thrown{   MapAVLNode<Key,Value>* ptr;   if (root == NULL)  // No such key. So add it.   {     return add(key);   }   ptr = root;   while( true )   {     if (ptr->key == key)     {        return ptr->value;     }     if (ptr->key < key)     {        if (ptr->right == NULL)  // No such key. So add it.        {           return add(key);        }        ptr = ptr->right;     }     else     {        if (ptr->left == NULL)  // No such key. So add it.        {           return add(key);        }        ptr = ptr->left;     }   }}
template <class Key, class Value>
Value& MapAVL<Key,Value>::add( const Key& key )
// Private helper function that adds a key to a tree.
// PRE:   key has been initialized
// POST:  If key is not already in the tree, then it is added.
//        otherwise map is not changed.
// Exception: if not enough memory to add key, map_full exception is thrown
{
   bool  taller;         // Tree taller flag
   
   try
   {
      root = addNode( root, key, taller );
   }
   catch( bad_alloc& )
   {
      throw map_full();
   }

   return (*this)[key];
}


template <class Key, class Value>
MapAVLNode<Key,Value>* MapAVL<Key,Value>::addNode( MapAVLNode<Key,Value>* tree, const Key& key, bool& taller )
// Private helper function that adds a key to a subtree.
// PRE:   key has been initialized 
// POST:  If key is not already in the tree, then it is added (and the new root returned)
//        otherwise map is not changed
//        Also, taller will be set according to whether the tree has grown taller or not.
{
   //  First possibility, root is NULL, so this is the bottom of the tree.
   //  Create a new leaf node, update it's information, and return

   if ( tree == NULL )
   {
      MapAbstract<Key,Value>::count++;
      tree = new MapAVLNode<Key,Value>;
      tree->key = key;
      tree->factor = EQ;
      tree->left = NULL;
      tree->right = NULL;
      taller = true;                    // Height of tree has increased
      return tree;                      // Return pointer to new node
   }

   //  Second possibility, the key stored at this node is the same as the
   //  key we want to add, so just return its address.

   if ( tree->key == key )
   {
      taller = false;                 // Height of tree unchanged
      return tree;
   }

   //  Third possibility, the key we want to insert is less than the
   //  key stored in the current node, so insert in the left subtree

   if ( tree->key > key )
   {
      tree->left = addNode( tree->left, key, taller );

      //  If the subtree grew in size, we must check to see if we are now
      //  unbalanced. As mentioned in class, there are three possible cases:
      //
      //  1. currently RH, so left subtree grew, so we are now EQ, and we
      //     report that this tree did not grow in height
      //  2. currently EQ, so left subtree grew, so we are now LH, and we
      //     report that this tree did grow in height
      //  3. currently LH, so left subtree grew, so we are out of balance,
      //     and must peform a rotation to bring ourselves back into balance
      //
      //  If the subtree didn't grow in size, than we didn't grow, either.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区二区视频在线观看| 欧美亚洲图片小说| 亚洲自拍偷拍麻豆| 午夜国产精品影院在线观看| 精品一区二区三区在线播放| 国产精品一二三四| 欧美一级片免费看| 亚洲私人黄色宅男| 亚洲大片一区二区三区| 91蜜桃免费观看视频| 这里只有精品电影| 一区二区三区鲁丝不卡| 不卡视频一二三四| 精品国偷自产国产一区| 成人免费一区二区三区在线观看| 麻豆极品一区二区三区| 一本久道久久综合中文字幕| 欧美v日韩v国产v| 国产乱理伦片在线观看夜一区| 中文字幕成人av| 国产黄色精品网站| 亚洲国产经典视频| 国产日韩成人精品| 成人激情免费电影网址| 国产激情视频一区二区在线观看 | 国产精品嫩草影院av蜜臀| 一区二区三区在线免费播放| 最新不卡av在线| 国产精品国产三级国产普通话99 | 亚洲自拍偷拍欧美| 亚洲精品视频在线| 欧美影片第一页| 欧美一区二区在线视频| 91精品婷婷国产综合久久性色| 91国偷自产一区二区开放时间| 樱花影视一区二区| 无码av中文一区二区三区桃花岛| 天天影视网天天综合色在线播放| 亚洲福利视频一区二区| 久久久久久久久久久电影| 亚洲一区二区三区四区中文字幕 | 午夜视频在线观看一区二区 | 亚洲精品一区二区三区福利| 久久久www免费人成精品| 欧美经典三级视频一区二区三区| 综合欧美一区二区三区| 亚洲一级在线观看| 精品亚洲免费视频| 成人国产一区二区三区精品| 欧美剧在线免费观看网站| 91碰在线视频| 欧美一卡2卡3卡4卡| 自拍视频在线观看一区二区| 久久99这里只有精品| 亚洲婷婷国产精品电影人久久| 国产麻豆日韩欧美久久| 老司机午夜精品| 欧美亚洲日本一区| 国产精品美女久久久久aⅴ| 韩国av一区二区| 天天射综合影视| 9人人澡人人爽人人精品| 国产成人99久久亚洲综合精品| 成人涩涩免费视频| 国产传媒一区在线| 久久久影视传媒| 国产在线播精品第三| 国产夜色精品一区二区av| 亚洲天堂网中文字| 不卡av在线免费观看| 国产亚洲制服色| 97久久精品人人澡人人爽| 69堂精品视频| 国模大尺度一区二区三区| 91精品国产综合久久蜜臀| 老司机午夜精品| 精品成人在线观看| www.成人网.com| 国产精品久久久久影视| 色94色欧美sute亚洲线路一ni| 亚洲国产欧美在线| 欧美第一区第二区| 亚洲妇熟xx妇色黄| 精品美女在线观看| 99国内精品久久| 五月天视频一区| 国产视频911| 欧美老肥妇做.爰bbww视频| 国产激情偷乱视频一区二区三区| 亚洲视频一二三区| 51精品秘密在线观看| 成人精品高清在线| 国产精品资源站在线| 夜夜精品视频一区二区 | 欧美老年两性高潮| 成人美女视频在线观看18| 亚洲五月六月丁香激情| 国产精品人妖ts系列视频| 日韩一级大片在线| 欧美性生交片4| 欧美三级欧美一级| 三级不卡在线观看| 欧美喷潮久久久xxxxx| 亚洲成人av福利| 亚洲男女毛片无遮挡| 在线观看视频91| 美国三级日本三级久久99| 亚洲资源在线观看| 国产精品久久久久一区二区三区| 日韩一级黄色片| 日韩你懂的电影在线观看| 91精品国产麻豆国产自产在线 | 国产精品高潮呻吟久久| 国产欧美日韩中文久久| 欧美国产精品v| 日韩一区在线看| 亚洲国产视频一区| 日本人妖一区二区| 国产精品理伦片| 精品国产伦一区二区三区观看体验| 欧美女孩性生活视频| 91精品国产福利| 久久亚洲一级片| 欧美性生活大片视频| 日韩视频中午一区| 国产精品网友自拍| 日本美女一区二区三区视频| 国产高清精品久久久久| 在线免费观看一区| 日韩精品资源二区在线| 中文成人综合网| 精久久久久久久久久久| 一本久久a久久精品亚洲| 26uuu色噜噜精品一区二区| 一区精品在线播放| 国产制服丝袜一区| 欧美二区三区的天堂| 亚洲人吸女人奶水| 国产91露脸合集magnet | 一本大道久久a久久综合婷婷| 日韩精品一区国产麻豆| 亚洲国产一区二区在线播放| 成人动漫av在线| 久久品道一品道久久精品| 日韩1区2区3区| 91精品国产色综合久久不卡蜜臀| 久久精品人人做| 国产亚洲1区2区3区| 亚洲成人动漫av| 日本福利一区二区| 中文在线一区二区| 国产伦精品一区二区三区视频青涩| 欧洲亚洲国产日韩| 国产欧美久久久精品影院| 婷婷久久综合九色综合绿巨人 | 亚洲黄色免费网站| 大胆欧美人体老妇| 色女孩综合影院| 中文字幕一区二区三区蜜月 | 一区二区三区在线视频播放| 97精品电影院| 国产精品嫩草99a| 成人听书哪个软件好| 久久欧美中文字幕| 成人免费黄色在线| 一区二区激情视频| 色综合久久天天| 午夜精品免费在线| 欧美一卡2卡三卡4卡5免费| 国产最新精品免费| 精品福利在线导航| 蜜臀av一区二区在线观看| 久久久综合网站| av在线不卡观看免费观看| 天天色天天操综合| 日韩三级免费观看| 久久激情五月婷婷| 中文字幕亚洲电影| 91精品国产综合久久久蜜臀粉嫩 | aaa欧美大片| 麻豆高清免费国产一区| 日韩一区二区精品在线观看| 国产自产高清不卡| 亚洲一二三级电影| 久久久99精品久久| 欧美剧情片在线观看| 97se亚洲国产综合在线| 午夜精品久久久久久久久久久 | 一区二区三区四区激情| 日韩欧美一级片| 91猫先生在线| 成人成人成人在线视频| 激情图片小说一区| 免费成人av资源网| 欧美在线小视频| 国产一区二区视频在线播放| 亚洲最新在线观看| 国产精品美日韩| 日韩三级高清在线| 8v天堂国产在线一区二区|