亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
日韩电影一区二区三区四区| 国产精品白丝jk白祙喷水网站 | 一本大道综合伊人精品热热 | 久久久久一区二区三区四区| 在线观看日韩国产| 国产老妇另类xxxxx| 午夜久久久久久| 综合分类小说区另类春色亚洲小说欧美| 91麻豆精品久久久久蜜臀| 99在线精品免费| 国产成人a级片| 美女网站视频久久| 亚洲国产精品久久人人爱| 亚洲欧洲日产国产综合网| 久久久国际精品| 精品少妇一区二区三区在线播放 | 欧美一级黄色录像| 日本精品裸体写真集在线观看| 国产精品69毛片高清亚洲| 蜜桃一区二区三区四区| 天堂午夜影视日韩欧美一区二区| 亚洲精品免费在线| 国产精品久久久久aaaa樱花| 久久免费午夜影院| 精品入口麻豆88视频| 日韩一区二区三区四区| 91麻豆精品国产91久久久 | 欧美日韩一区不卡| 99久久99久久久精品齐齐| 国产成人高清在线| 国产精品影视网| 国产美女在线精品| 国产成人亚洲综合a∨猫咪| 国产精品18久久久久久久久久久久| 免费人成在线不卡| 老司机午夜精品99久久| 裸体健美xxxx欧美裸体表演| 麻豆精品一区二区| 久久99久久久欧美国产| 久久99久久久久久久久久久| 精品一区二区三区在线播放| 久久99热狠狠色一区二区| 精品无人码麻豆乱码1区2区| 国内精品伊人久久久久av一坑 | 欧美亚洲动漫制服丝袜| 91福利精品视频| 91激情五月电影| 欧美日韩在线播放一区| 欧美巨大另类极品videosbest | 精品国产麻豆免费人成网站| 欧美r级在线观看| 国产视频一区在线播放| 国产精品卡一卡二| 亚洲精品国产品国语在线app| 一区二区三区不卡视频| 午夜精品久久久久久久久久| 麻豆国产精品一区二区三区 | 国产在线精品国自产拍免费| 国产成人综合网站| 99久久久精品免费观看国产蜜| 99re66热这里只有精品3直播| 色综合久久久久综合99| 666欧美在线视频| 欧美精品一区二区三区高清aⅴ| 2023国产精华国产精品| 国产精品国产三级国产普通话三级| 亚洲欧美一区二区久久| 一区二区三区精品| 蜜臀久久99精品久久久久久9 | 国产又粗又猛又爽又黄91精品| 国产成人亚洲综合a∨婷婷图片 | 久久久精品免费网站| 亚洲日本va午夜在线影院| 亚洲激情在线激情| 免费在线看成人av| 成人av一区二区三区| 欧美日韩国产影片| 亚洲国产精品传媒在线观看| 一区二区久久久久久| 麻豆国产精品视频| 在线视频中文字幕一区二区| 日韩精品一区国产麻豆| 国产精品国产三级国产| 美女脱光内衣内裤视频久久网站| 国产成人在线免费观看| 5月丁香婷婷综合| 国产精品久久久久aaaa| 欧美a级一区二区| 91在线观看地址| 精品国产电影一区二区| 一区二区三区精密机械公司| 国产一区二区伦理片| 欧美日韩电影在线播放| 国产精品私人影院| 久久精品99国产国产精| 色噜噜狠狠成人网p站| 久久久久88色偷偷免费 | 99精品黄色片免费大全| 欧美成人三级电影在线| 亚洲综合小说图片| 国产aⅴ精品一区二区三区色成熟| 精品视频999| 自拍偷拍欧美精品| 国产精品 日产精品 欧美精品| 欧美日韩电影在线播放| 亚洲免费在线观看| 丰满亚洲少妇av| 久久综合狠狠综合久久激情 | 久久久99精品免费观看| 三级久久三级久久久| 色老汉av一区二区三区| 亚洲欧洲精品一区二区三区 | 欧美精品v国产精品v日韩精品 | 综合在线观看色| 国产盗摄精品一区二区三区在线| 欧美一二三四区在线| 天天综合日日夜夜精品| 欧美性视频一区二区三区| 亚洲日本丝袜连裤袜办公室| 高清不卡一区二区在线| 日韩欧美一区二区免费| 日本午夜精品视频在线观看| 欧美日韩一区二区在线观看视频| 中文字幕中文字幕一区二区| 福利电影一区二区| 国产精品免费久久久久| 国产成人亚洲精品狼色在线| 久久亚洲一区二区三区四区| 狠狠色狠狠色综合日日91app| 日韩女优电影在线观看| 久久国产尿小便嘘嘘| 日韩女同互慰一区二区| 久久国产人妖系列| 337p粉嫩大胆噜噜噜噜噜91av| 久久99精品久久久久婷婷| 欧美xxx久久| 国产精品一区免费在线观看| 精品成人私密视频| 国产福利91精品| 国产精品久久久久久久久免费丝袜| 丁香婷婷综合激情五月色| 国产欧美一区二区精品忘忧草| 丰满少妇久久久久久久| 亚洲日本丝袜连裤袜办公室| 欧洲精品一区二区三区在线观看| 亚洲黄色片在线观看| 欧美日韩国产a| 六月婷婷色综合| 久久婷婷一区二区三区| 成人免费观看视频| 亚洲欧美日韩系列| 在线不卡a资源高清| 久久99久久久久久久久久久| 久久午夜老司机| 91在线小视频| 亚洲h在线观看| 久久综合九色综合久久久精品综合| 国产白丝精品91爽爽久久| 亚洲欧美偷拍另类a∨色屁股| 在线免费观看日韩欧美| 日韩福利视频导航| 国产欧美日韩亚州综合 | 国产精品久久久久国产精品日日| 99精品视频在线观看| 亚洲第一福利一区| 精品久久久久一区二区国产| 国产成人午夜高潮毛片| 亚洲一区二区美女| 精品国产不卡一区二区三区| 成人av在线观| 日本成人在线电影网| 国产欧美中文在线| 欧美三区在线观看| 国产美女在线精品| 一区二区久久久| 久久久久久亚洲综合影院红桃| 色综合咪咪久久| 精品一区二区三区的国产在线播放| 国产精品你懂的| 日韩一卡二卡三卡| 色婷婷综合久久久| 狠狠色狠狠色综合日日91app| 亚洲免费大片在线观看| 欧美成人一区二区| 欧美伊人久久大香线蕉综合69| 国产乱对白刺激视频不卡| 亚洲电影你懂得| 国产精品久久久久一区二区三区| 91麻豆精品国产91久久久久久| www.性欧美| 精品亚洲aⅴ乱码一区二区三区| 亚洲三级免费观看| 国产色91在线| 91精品国产综合久久蜜臀| 91在线精品秘密一区二区| 韩国v欧美v亚洲v日本v| 午夜精品一区二区三区三上悠亚| 国产精品麻豆久久久| 亚洲精品一区二区三区在线观看 | 国产欧美日韩不卡免费|