Exemple #1
0
void BST::insertItem(TreeNode *& treePtr,
                     const TreeItemType& newItem)
                     throw(TreeException)

{
   if (treePtr == NULL)
   {  // position of insertion found; insert after leaf

      // create a new node
      treePtr = new TreeNode(newItem, NULL, NULL);
   }
   // else search for the insertion position
   else if (newItem.getKey() < treePtr->item.getKey())
      // search the left subtree
      insertItem(treePtr->leftChildPtr, newItem);

   else if(newItem.getKey() > treePtr->item.getKey())
      // search the right subtree
      insertItem(treePtr->rightChildPtr, newItem);
   else
     throw TreeException("Attempted to insert duplicate key.");
}  // end insertItem
Exemple #2
0
/*
Function Name: saveVisit
Purpose: Visit function to be used
with quit for saving each node.
*/
void saveVisit(TreeItemType& suspect, ofstream& stream)
{
  string a_string, keyName;
  keyName = suspect.getKey();
  upCase(keyName);
  int numberofAttr = suspect.attributes.getLength();
  //increment number of attributes for loop condition
  ++numberofAttr;
  stream << "Name:" << endl;
  stream << keyName << endl;
  stream << "Attributes:" << endl;
  for(int i = 1; i<numberofAttr; ++i){
    suspect.attributes.retrieve(i, a_string);
    upCase(a_string);
    stream << a_string << endl;
  }
  stream << "$" << endl;
  return;
}
QList<UserItem*>
UserSelectView::GetSelectedUserItems()
{
        QList<UserItem*> selList;
        int topCount = this->topLevelItemCount();
        for (int i = 0; i < topCount; i++)
        {
                TreeItemType* topi = this->topLevelItem(i);
                int csCount = topi->childCount();
                for (int j = 0; j < csCount; j++)
                {
                        TreeItemType* chld = topi->child(j);
                        if (chld->checkState(0) == Qt::Checked)
                        {
                                QString const& key = chld->data(0, UserItemRole).toString();
                                if (UserItem* u = m_collection->value(key, 0))
                                {
	                                selList << u;
                                }
                        }
                }
        }
        return selList;
}