本文整理汇总了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;
}
}
//.........这里部分代码省略.........