Exemplo n.º 1
0
    void remove(const KeyType& key, NodePtr parent) {

      if(root != nullptr) {

        if(root->key == key) {
          removeRootMatch();
      
        } else {
          if(key < parent->key && parent->left != nullptr) {
            if(parent->left->key == key) {
              removeMatch(parent,parent->left,true);
            } else {
              remove(key,parent->left);
            }            
          } 
          else if(key > parent->key & parent->right != nullptr) {
            if(parent->right->key == key) {
              removeMatch(parent,parent->right,false);
            } else {
              remove(key,parent->right);
            }            
          }
          else {
            std::cout << "Key " << key << "not found" << std::endl; 
          }
        }
      } else {
        std::cout << "The tree is empty" << std::endl;
      }   
    }
Exemplo n.º 2
0
TEST(MatchDao, saveTeams){
    //precisa de um player, id 0
    auto connection = loadConnection();
    mm::Match match;
    vector<int> teamA;
    teamA.push_back(1);
    teamA.push_back(1);
    vector<int> teamB;
    teamB.push_back(1);
    match.addTeam(teamA);
    match.addTeam(teamB);

    auto matchDao = connection->matchDao();
    bool saved = matchDao->saveMatch(match);
    EXPECT_TRUE(saved);

    mm::Match loadedMatch;
    loadedMatch.setId(match.id());
    bool loaded = matchDao->loadMatch(loadedMatch);
    if(!loaded){
        std::cout << "ERRO: " << matchDao->getError() << std::endl;
    }

    EXPECT_TRUE(loaded);

    int playersCount = loadedMatch.playersCount();
    int teamsCount = loadedMatch.teamsCount();

    EXPECT_EQ(3, playersCount);
    EXPECT_EQ(2, teamsCount);

    bool removed = matchDao->removeMatch(match);
    EXPECT_FALSE(removed);//match_profile dependencies

}
Exemplo n.º 3
0
void Trees::removeNodep(int data, Node* parent)
{
    //If the tree was NOT Empty
    if(root != NULL)
    {
        //If the data was found / delete
        if(root->data == data)
        {
            removeRootMatch();
        }

        //If the data was not found
        else
        {
            //Left child (less than n)
            if(data < parent->data && parent->left != NULL)
            {
                parent->left->data == data ?
                removeMatch(parent, parent->left, true):
                removeNodep(data, parent->left);
            }

            //Right child (greater than n)
            else if(data > parent->data && parent->right != NULL)
            {
                parent->right->data == data ?
                removeMatch(parent, parent->right, false):
                removeNodep(data, parent->right);
            }
            else
            {
                cout << "The data " << data << " was not found in the current tree." << endl;
            }
        }
    }

    //If the tree is empty
    else
    {
        cout << "The tree is empty." << endl;
    }
}
Exemplo n.º 4
0
bool MyMoneySplit::replaceId(const QString& newId, const QString& oldId)
{
  bool changed = false;

  if (m_payee == oldId) {
    m_payee = newId;
    changed = true;
  } else if (m_account == oldId) {
    m_account = newId;
    changed = true;
  }

  if (isMatched()) {
    MyMoneyTransaction t = matchedTransaction();
    if (t.replaceId(newId, oldId)) {
      removeMatch();
      addMatch(t);
      changed = true;
    }
  }

  return changed;
}