本文整理汇总了C++中BinTree类的典型用法代码示例。如果您正苦于以下问题:C++ BinTree类的具体用法?C++ BinTree怎么用?C++ BinTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RemoveDeadTransports
//
// FindTransports
//
// Find a suitable list of transports for this squad
//
void Transport::Manager::FindTransports(Script &script)
{
// We have a number of slots we need (provided by the number of units in the squad)
// Use the transports closest to the squad first
U32 slots = script.GetSquad()->GetList().GetCount();
BinTree<Transport, F32> transports;
// Get the current location of the suqad
Vector location;
if (script.GetSquad()->GetLocation(location))
{
// Make sure that there's no dead transports lingering around
RemoveDeadTransports();
// Sort the transports by distance from the squad
for (NBinTree<Transport>::Iterator i(&idle); *i; i++)
{
transports.Add((location - (**i)->Origin()).Magnitude2(), *i);
}
// Now itereate the sorted transports and assign them to the script
for (BinTree<Transport, F32>::Iterator t(&transports); *t; t++)
{
Transport &transport = **t;
// Assign this transport to the script
transport.AssignToSquad(&script);
// How many slots does this transport provide ?
U32 available = transport->TransportType()->GetSpaces();
if (available >= slots)
{
slots = 0;
break;
}
// We still have slots to go .. keep looking
slots -= available;
}
// We're out of transports, did we get enough ?
if (slots)
{
// We didn't get enough, notify the script
script.Notify(0x3BBBD1F7); // "Transport::NotEnough"
}
else
{
// We got enough, notify the script
script.Notify(0x9BA84E05); // "Transport::Enough"
}
transports.UnlinkAll();
}
}
示例2: addItem
// ---------------------------------------------------------------------------
// addItem()
// Takes the Item and addes to the hash table using the movieCode as a key to
// hash function approiatly
bool Inventory::addItem(Item *item, char movieCode)
{
BinTree *storageTree = storage[hash(movieCode)];
storageTree->insert(item);
return true;
}
示例3: testIterator
void testIterator ()
{
BinTree<int> t;
t.insertBOT(59)
.insertBOT(23)
.insertBOT(68)
.insertBOT(190)
.insertBOT(41)
.insertBOT(67);
BinTree<int>::LeftRootRightIterator it = t.begin();
assert (*it == 23);
++it;
++it;
assert (*it == 59);;
int count = 0;
for (it = t.begin(); it != t.end(); ++it)
{
count++;
}
assert (count == 6);
}
示例4: main
int main ()
{
testMember ();
testAssignment();
testMinEl();
testIterator();
BinTree<int> t;
t.insertBOT(56)
.insertBOT(23)
.insertBOT(68)
.insertBOT(190)
.insertBOT(41)
.insertBOT(60)
.insertBOT(65)
.insertBOT(59);
cerr << "digraph G{" << endl;
t.dottyPrint (cerr);
cerr << "}\n";
prettyPrint<int> (t.rootIter());
testMakeTree();
return 0;
}
示例5: retrieveItem
// ---------------------------------------------------------------------------
// retrieveItem
// Takes the Item and compares it's value in the correct BinTree found after
// using itemCode to hash to correct key
Item* Inventory::retrieveItem(const Item *obj, char itemCode) const
{
BinTree *storageTree = storage[hash(itemCode)];
Item *retrieved = NULL;
storageTree->retrieve(obj, retrieved);
return retrieved;
}
示例6: equalityHelper
// overloaded equality operator ==
bool BinTree::operator==(const BinTree &otherTree) const {
// case 1: both trees are empty
if ( isEmpty() && otherTree.isEmpty() ) {
return true;
} else if (isEmpty() || otherTree.isEmpty()){
return false;
} else {
return equalityHelper(root,otherTree.root);
}
}
示例7: testMember
void testMember ()
{
BinTree<int> t;
t.add(10,"").add(12,"L").add(14,"R").add(15,"LR");
assert (t.member(12) == true);
assert (t.member(18) == false);
assert (t.member(15) == true);
}
示例8: main
int main (int argc, char *argv[])
{
string treestr("one two three # # # four five six # seven # # # eight nine # # #\n");
istringstream sin(treestr);
BinTree<string> tree;
sin >> tree;
cout << tree << endl;
cout << "先序输出:" << endl;
cout << "0. ";
tree.preorder_traverse();
cout << "1. ";
tree.preorder_traverse_nore();
cout << "2. ";
tree.preorder_traverse_nore2();
cout << "3. ";
tree.preorder_traverse_nore3();
cout << "中序输出:" << endl;
cout << "1. ";
tree.inorder_traverse_nore();
cout << "2. ";
tree.inorder_traverse_nore2();
cout << "后序输出:" << endl;
tree.postorder_traverse();
cout << "层序输出:" << endl;
tree.levelorder_traverse();
return EXIT_SUCCESS;
} // ---------- end of function main ----------
示例9: main
int main()
{
FILE* f = fopen("example.txt", "r");
BinTree<char> tree;// = BinTree<char>();
Node<char>* pos = tree.Root;
add(f, pos, true);
tree.traverseInfix(tree.Root);
system("pause");
return 0;
}
示例10: main
int main()
{
BinTree<char> t;
t.input(v, 29);
// t.output();
// t.preorder_traversal();
// t.inorder_traversal();
// t.postorder_traversal();
t.print_path();
return 0;
}
示例11: testMinEl
void testMinEl ()
{
BinTree<int> t;
t.insertBOT(59)
.insertBOT(23)
.insertBOT(68)
.insertBOT(190)
.insertBOT(41)
.insertBOT(67);
assert (t.minelement() == 23);
}
示例12: testMakeTree
void testMakeTree ()
{
BinTree<int> t;
typename BinTree<int>::HierarchicalIterator it = t.rootIter();
*it = 10;
*it.goLeft() = 12;
*it.goRight() = 14;
*it.goRight().goLeft() = 20;
prettyPrint<int> (it);
}
示例13: Output
void Output(BinTree<char> &B)
{
int num;
MyQueue<char> Q;
B.InOrderInMirror(B.root,Show,Q);
int i=0;
char arr[DEFAULTSIZE];
B.PreOrder(B.root,arr,i);
while (!Q.IsEmpty())
{
num=NumCal(arr,Q.getFront());
for (i=1;i<num;i++) cout<<" ";
cout<<Q.DeQueue()<<endl;
}
}
示例14: main
int main()
{
char* str = "123##4##5#6###";
char* str1 = "23##5###";
char* str2 = "472##5##8##";
BinTree<char> mytree;
BinTree<char> rtree;
mytree.createTree(str2);
// rtree.createTree(str1);
// mytree.mirrorTree();
mytree.preOrder();
mytree.sumData(12);
return 0;
}
示例15: main
int main(int argn, char *argc[])
{
int n = 1000;
unsigned int t = time(0);
int value;
if (argn > 1)
n = atoi(argc[1]);
if (argn > 2)
t = atoi(argc[2]);
srand(t);
cout << "writeBinTree " << n << " " << t << endl;
BinTree<int> tree;
BinTree<int>::Node *node;
int i;
for (i = 0; i < 30; i++)
{
do
{
value = (int) (500.0*rand()/(RAND_MAX+1.0));
node = tree.search(value);
} while (node not_eq NULL);
node = new BinTree<int>::Node (value);
tree.insert(node);
}
preOrderRec(tree.getRoot(), print_ex);
inOrderRec(tree.getRoot(), print_tex);
destroyRec(tree.getRoot());
for (i = 0; i < n; i++)
{
do
{
value = (int) (n*10.0*rand()/(RAND_MAX+1.0));
node = tree.search(value);
} while (node not_eq NULL);
node = new BinTree<int>::Node (value);
tree.insert(node);
}
preOrderRec(tree.getRoot(), print_key);
destroyRec(tree.getRoot());
}