当前位置: 首页>>代码示例>>C++>>正文


C++ BST::ShowTree方法代码示例

本文整理汇总了C++中BST::ShowTree方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::ShowTree方法的具体用法?C++ BST::ShowTree怎么用?C++ BST::ShowTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BST的用法示例。


在下文中一共展示了BST::ShowTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  string comment ;
  char choice ;
  KeyType key, newKey ;
  NodePtr x ;
  NodePtr y ;
  BST T ;

  bool interact = false ;
  bool printExtract = true ;

  if ( interact ) cout << "Choose: (c)onstruct, (i)nsert, (d)elete, "
	  << "(s)earch, (S)how, P(rint), " 
	  << "(m)inimum, (e)extract min, decrease (k)ey, "
	  << "+/- turns extract print on/off: " ; 
  cin >> choice ;
  while ( !cin.eof() ) {
    switch ( choice ) {
      case 'c': 
		// This has already been done above.
		// Calling a constructor within a switch causes problems.
                break ;
      case 'i': {
                if ( interact ) cout << "Enter key value to insert: " ;
                cin >> newKey ;
                NodePtr z = new Node( newKey ) ;
                T.BSTinsert( z ) ;
                } break ;
      case 'd':
                if ( interact ) cout << "Enter key value to delete: " ;
                cin >> key ;
                x = T.BSTsearch( T.root, key ) ;
		if ( x != NIL ) {
		   T.BSTdelete( x ) ;
                   delete x ;
                } else {
		   cout << "No " << key << " key, can't delete" << "\n\n" ;
		}
                break ;
      case 's':
                if ( interact ) cout << "Enter key value to search for: " ;
                cin >> key ;
                x = T.BSTsearch( T.root, key ) ;
		if ( x != NIL ) {
                   cout << "key, " << key << ", found" << "\n\n" ;
                } else {
		   cout << "key, " << key << ", not found" << "\n\n" ;
		}
                break ;

/*			This is not used directly in the tests
      case 'm': 
                z = T.BSTminimum() ;
                cout << "Minimum = " << key << "\n\n" ;
                break ;
*/
/*			The following two are not used in BST's
      case 'e': 
                if ( T.heapSize > 0 ) {
                   key = T.extractMin( ) ;
                   if ( printExtract ) 
                      cout << "Minimum extracted = " << key << "\n" ;
                } else {
                   cout << "Tree empty, can't extract minimum.\n\n" ;
                }
                break ;
      case 'k': 
                if ( interact ) cout << "Enter key to decrease and new key: " ;
                cin >> key >> newKey ;
                i = T.BSTsearch( key ) ;
                if ( i > 0 ) {
                   T.decreaseKey( i, newKey ) ;
		} else {
                   cout << "Originaly key = " << key << "not in heap.\n\n" ;
		}
                break ;
*/
      case 'S': 
		cout << "Structure of tree (rotated 90 degrees to left):\n\n" ;
		T.ShowTree( T.root, 0 ) ;
		cout << "\n\n" ;
                break ;
      case 'P': 
		T.PrintTree( ) ;
                break ;
/*
      case '+': 
		printExtract = true ;
                break ;
      case '-': 
		printExtract = false ;
                break ;
*/
      case '#': 
		cout << '#' ; getline(cin, comment) ;
                cout << comment << "\n\n" ;
                break ;
      default: 
		cout << "Illegal choice: " << choice << endl ;
//.........这里部分代码省略.........
开发者ID:Sandarmann,项目名称:Programming,代码行数:101,代码来源:cmdInt.cpp


注:本文中的BST::ShowTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。