//
  // 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();
    }

  }
Esempio n. 2
0
// ---------------------------------------------------------------------------
// 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; 
}
Esempio n. 3
0
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);

}
Esempio n. 4
0
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;
}
Esempio n. 5
0
// ---------------------------------------------------------------------------
// 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; 
}
// 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);
 }
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
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  ----------
Esempio n. 9
0
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;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
void testMinEl ()
{
	BinTree<int> t;

	t.insertBOT(59)
	 .insertBOT(23)
	 .insertBOT(68)
	 .insertBOT(190)
	 .insertBOT(41)
	 .insertBOT(67);

	 assert (t.minelement() == 23);
}
Esempio n. 12
0
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);

}
Esempio n. 13
0
  //
  // Process a CreateCursor scope
  //
  void ProcessCreateCursor(FScope *fScope)
  {
    // Cursor name is first argument
    const char *name = fScope->NextArgString();

    // Cursor class is second argument
    const char *cls  = fScope->NextArgString();

    // Create the cursor
    Base *newCrs = NULL;
    U32 key = Crc::CalcStr(cls);

    switch (key)
    {
      case 0x5B2A0A5F: // "Null"
        newCrs = new Base;
        break;

      case 0xE04B5BBC: // "Bitmap"
        newCrs = new Bmp;
        break;

      case 0xE5A51519: // "Geometric"
        newCrs = new Geometric;
        break;

      default:
      {
        Base *derived;

        if ((derived = cursors.Find(key)) != NULL)
        {
          newCrs = new Derived(derived);
        }
        else
        {
          LOG_ERR(("Unknown Cursor Class [%s]", cls));
          return;
        }
        break;
      }
    }

    // Configure the cursor
    newCrs->Configure(fScope);

    // Add it to the list
    cursors.Add(Crc::CalcStr(name), newCrs);
  }
Esempio n. 14
0
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;
    }
}
Esempio n. 15
0
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;
}
Esempio n. 16
0
  //
  // Set the cursor to be the active cursor
  // Specifying 0 will use the system default cursor
  //
  Bool Set(U32 id)
  {
    ASSERT(sysInit);

    // If id is 0 use the default cursor
    if (id == 0)
    {
      id = standardCrs[0];
    }

    Base *crs = cursors.Find(id);

    if (crs != NULL)
    {
      if (crs != current)
      {
        // Shutdown current
        if (current)
        {
          current->Notify(Base::CN_DEACTIVATE);
        }

        // Start the cursor
        current = crs;
        current->Notify(Base::CN_ACTIVATE);
      }
      return (TRUE);
    }
    else
    {
      return (FALSE);
    }
  }
Esempio n. 17
0
 void Print(int x) { // just for trace/debug the program
     int y = x;
     if (this) {
         while (x > 0) {
             cout << " ";
             x--;
         }
         cout << stateName[data] << endl;
         if (left) {
             left->Print(y+1);
         }
         if (right) {
             right->Print(y);
         }
     }
 };
Esempio n. 18
0
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());
}
Esempio n. 19
0
int main() {
	BinTree<string, int> yankees;

	yankees.Append("Ichiro", 31);
	yankees.Append("Jeter", 2);
	yankees.Append("Cano", 24);
	yankees.Append("Teixeira", 25);
	yankees.Append("Granderson", 14);
	yankees.Append("Nix", 17);
	yankees.Append("Chavez", 12);
	yankees.Append("A.Jones", 22);
	yankees.Append("Martin", 55);

	yankees.Dump();

	return 0;
}
Esempio n. 20
0
int main(int argc, char** argv)
{
    srand(time(0));
    
    
    BinTree tree;
    
    cout << "Inserting 6 nodes with random values: " << endl;
    tree.insertNode(rand()%100+1);
    tree.insertNode(rand()%100+1);
    tree.insertNode(rand()%100+1);
    tree.insertNode(rand()%100+1);
    tree.insertNode(rand()%100+1);
    tree.insertNode(rand()%100+1);
    
    int x = rand()%100+1;
    tree.insertNode(x);
    cout << endl;
    
    cout << "Values displayed using in-order traversal: " << endl;
    tree.displayInOrder();
    cout << endl;
    
    cout << "Values displayed using pre-order traversal: " << endl;
    tree.displayPreOrder();
    cout << endl;
    
    cout << "Values displayed using post-order traversal: " << endl;
    tree.displayPostOrder();
    cout << endl;
    
    cout << "Deleting a node: value " << x << " removed." << endl;
    tree.remove(x);
    
    cout << "Values displayed using in-order traversal after deleting node: " << endl;
    tree.displayInOrder();
    cout << endl;
    
    
    
    
    
    

    return 0;
}
Esempio n. 21
0
void testAssignment()
{
	BinTree<int> t;

	t.add(10,"").add(12,"L").add(14,"R").add(15,"LR");
	simplePrint(t);

	BinTree<int> t1;

	t1 = t;

	assert (t1.member(10) && 
		    t1.member (12) && 
		    t1.member (14) && 
		    t1.member (15));


}
Esempio n. 22
0
bool FileIntersect::processUnsortedFiles()
{
	const QuickString &databaseFilename = _context->getDatabaseFileName();
	BinTree *binTree = new BinTree(_context->getDatabaseFileIdx(), _context);

	FileRecordMgr *queryFRM = new FileRecordMgr(_context->getQueryFileIdx(), _context);
	if (!queryFRM->open()) {
		return false;
	}

	if (!binTree->loadDB()) {
		fprintf(stderr, "Error: Unable to load database file %s.\n", databaseFilename.c_str());
		delete binTree;
		exit(1);
	}


    _context->determineOutputType();
    _recordOutputMgr->init(_context);

	while (!queryFRM->eof()) {
		Record *queryRecord = queryFRM->allocateAndGetNextRecord();
		if (queryRecord == NULL) {
			continue;
		}
		RecordKeyList hitSet(queryRecord);
		binTree->getHits(queryRecord, hitSet);
    	if (_context->getObeySplits()) {
    		RecordKeyList keySet(hitSet.getKey());
    		RecordKeyList resultSet;
    		_blockMgr->findBlockedOverlaps(keySet, hitSet, resultSet);
    		processHits(resultSet);
    	} else {
    		processHits(hitSet);
    	}
		queryFRM->deleteRecord(queryRecord);
	}
	queryFRM->close();

	//clean up.
	delete queryFRM;
	delete binTree;
	return true;
}
Esempio n. 23
0
    ///////////////////////////////////////////////////////////////////////////////
    //
    // Quake::CmdHandler
    //
    void CmdHandler(U32 pathCrc)
    {
      switch (pathCrc)
      {
      case 0x3860F45E: // "quake.active"
        if (*active)
        {
          effect->StopByEffect();
          effect->Play2D(Sound::Digital::DEFAULT_VOLUME, Sound::Digital::NO_OWNER, F32_MAX, 0);
          soundoff = FALSE;
          quakeAnim.SetFrame(0);
        }
        else
        {
          effect->StopByEffect();
          soundoff = TRUE;
        }
        break;

      case 0x030664FD: // "quake.type"
      {
        Type * t = typeList.Find( Crc::CalcStr( *typeVar));
        if (t)
        {
          SetCurrent( t);
        }
        break;
      }

      case 0x44327F38: // "quake.listtypes"
      {
        char *s = NULL;
        Console::GetArgString(1, s);

        U32 len = 0;
        if (s)
        {
          len = strlen(s);
        }

        // Registered quake types
        CON_DIAG(("[Quake Types]"))

        BinTree<Type>::Iterator i(&typeList);
        for (!i; *i; i++)
        {
          if (!s || !Utils::Strnicmp( (*i)->name.str, s, len))
	    	  {
    			  Console::Message("%s", (*i)->name.str);
          }
        }
        break;
      }
      //
      }   // switch( pathCrc)
    }
Esempio n. 24
0
int main()
{
	char* str = "123##4##56###";
	BinTree<char> mytree;
//	char* VLR = "123456";
//	char* LVR = "324165";
//	int len = strlen(VLR);
	mytree.CreatTree(str);
	mytree.zigzagLevelOrder();
//	mytree.RecPreOrder();
//	mytree.RecInOrder();
//	mytree.RecPostOrder();
//	mytree.LevelOrder();
//	mytree.PreOrder();
//	mytree.InOrder();
//	mytree.PostOrder();
//	mytree._CreatTree(VLR, LVR,len);
	system("pause");
	return 0;
}
Esempio n. 25
0
int main()
{
    //Binary tree traversal
    BinTree tree;
    Node h = {8, NULL, NULL};
    Node g = {7, NULL, &h};
    Node f = {6, NULL, NULL};
    Node e = {5, &f, &g};
    Node d = {4, NULL, &e};
    Node c = {3, NULL, NULL};
    Node b = {2, &d, NULL};
    Node a = {1, &b, &c};
    tree.SetRoot(&a);

    cout << "Preorder traverse" << endl;
    tree.PreorderTraverse();
    cout << "Inorder traverse" << endl;
    tree.InorderTraverse();
    cout << "Postorder traverse" << endl;
    tree.PostorderTraverse();

}
Esempio n. 26
0
void SearchTree<Key,Data>::voegtoe(BinTree<Key,Data>& node, const Key& sl,const Data& data){
    BinTree<Key,Data> *kind;
    if (sl < node->sl)
        kind=&(node->left);
    else
        kind=&(node->right);
    if (*kind == 0){
        (*kind) = move((unique_ptr<BinNode<Key,Data>>) new BinNode<Key,Data>(sl,data));
        (*kind)->parent = node.get();
    }
    else
        voegtoe(*kind, sl,data);
}
Esempio n. 27
0
  //
  // Find a cursor by name
  //
  U32 FindByName(const char *name)
  {
    U32 id = Crc::CalcStr(name);

    // Ensure the cursor exists
    if (cursors.Find(id))
    {
      return (id);
    }
    else
    {
      LOG_ERR(("Cursor [%s] not found", name));
      return (0);
    }
  }
Esempio n. 28
0
//------------------------------------------------ setCustomer()
void Borrow::setCustomer(istream& in, BinTree& cust) {
	int customerID = 0;
	in >> customerID;
	Customer target(customerID);	// empty instance with only id
	Generic* customerInStore = NULL;
	
	cust.retrieve(target, customerInStore);
	// pointer is now modified to point to the customer in our store
	if(customerInStore != NULL) {	// if found
		// down-cast and store reference
		customer = dynamic_cast<Customer*>(customerInStore);
	} else {
		customer = NULL;
	}
	// target goes out of scope and gets destroyed
}
Esempio n. 29
0
void buildTree(BinTree& T, ifstream& infile) {
	string s;

	for (;;) {
		infile >> s;
		cout << s << ' ';
		if (s == "$$") break;                // at end of one line
		if (infile.eof()) break;             // no more lines of data
		NodeData* ptr = new NodeData(s);     // NodeData constructor takes string
		// would do a setData if there were more than a string

		bool success = T.insert(ptr);
		if (!success)
			delete ptr;                       // duplicate case, not inserted
	}
}
Esempio n. 30
0
  //
  // Delete all cursors
  //
  void DeleteAll()
  {
    ASSERT(sysInit);

    // Unset the current cursor
    current = NULL;

    // Clear standard cursors
    for (int i = 0; i < MAX_CURSORS; i++)
    {
      standardCrs[i] = 0;
    }

    // Delete all cursors
    cursors.DisposeAll();
  }