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


C++ SplayTree::inorder方法代码示例

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


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

示例1: main

int main(int argc, char** argv)
{

    if (argc != 2) {
        cerr << "Provide the music file to process as an argument to the program." << endl;
        cerr << "Usage: " << argv[0] << " <filename>" << endl;
        exit(1);
    }
    
    // key --> artist name (string)
    // value --> Array of songs (array of strings)
    SplayTree<string, Array<string> > splayTree;
  
    ifstream ifs(argv[1]);
    string line;
    while(getline(ifs, line)) {
        string artist, musicEntry;
        processInput(line, artist, musicEntry);
        insertWithGrouping(splayTree, artist, musicEntry);
    }

    // Dump the initial splay tree
    dumpSplayTree(splayTree, "splay_tree0.dot");

    int count = 0;
    // Insertion into the splay tree is done
    // Now, let's go through the motions of inserting, deleting or finding
    while (true) {
        int input;
        ostringstream os;
        os << "splay_tree" << ++count << ".dot";
        string filename = os.str();
        cout << "Input choices:" << endl;
        cout << "* Insert (1)" << endl;
        cout << "* Find (2)" << endl;
        cout << "* Remove (3)" << endl;
        cout << "* Print sorted (4)" << endl;
        cout << "* Exit(0)" << endl;
        cin >> input;
        cin.ignore(256, '\n');
        switch(input) {
          case 1: {
              string artist, musicEntry;
              cout << "Artist: ";
              getline(cin, artist);
              cout << "Music: ";
              getline(cin, musicEntry);
              insertWithGrouping(splayTree, artist, musicEntry);
              dumpSplayTree(splayTree, filename);
              cout << "Done." << endl;
              break; 
          }
          case 2: {
              cout << "Find what (Enter artist name): ";
              string artist;
              getline(cin, artist);
              BSTNode<string, Array<string> >* approxMatchNode_lb = nullptr;
              BSTNode<string, Array<string> >* approxMatchNode_ub = nullptr;
              BSTNode<string, Array<string> >* node = 
                  splayTree.findApprox(artist, approxMatchNode_lb, approxMatchNode_ub);
              dumpSplayTree(splayTree, filename);
              if (node != nullptr) {
                  cout << "Accurately matched!" << endl;
              } else {
                  cout << "Approximate matches: " << endl;
                  if (approxMatchNode_lb) {
                      cout << "Artist: " << approxMatchNode_lb->key() << endl;
                      cout << "Songs: " << approxMatchNode_lb->value() << endl;
                  }
                  if (approxMatchNode_ub) {
                      cout << "Artist: " << approxMatchNode_ub->key() << endl;
                      cout << "Songs: " << approxMatchNode_ub->value() << endl;
                  }
              }
              break;
          }
          case 3: {
              cout << "Remove what (Enter artist name): ";
              string artist;
              getline(cin, artist);
              splayTree.remove(artist);
              dumpSplayTree(splayTree, filename);
              cout << "Done." << endl;
              break; 
          }
          case 4: {
              cout << "Sorted List: " << endl;
              splayTree.inorder();
              cout << "Done." << endl;
              break; 
          }
          case 0: {
              cout << "Exiting..." << endl;
              return 0;
          }
          default: {
              cout << "Invalid entry: Try again." << endl;
              break;
          }
        }
//.........这里部分代码省略.........
开发者ID:hannahvoelker,项目名称:comp15-stuff,代码行数:101,代码来源:main.cpp


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