aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/sortresult.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2020-06-12 20:28:17 +0200
committerRenaud G <renaud@rolisteam.org>2020-06-12 20:28:17 +0200
commit615a7e3e5d8c85ef0eedbff4fa3a29ebeded92cd (patch)
treee1bd282b037e74b1068958e2e5f2d281bf83a63b /node/sortresult.cpp
parent9d322992515305edfd34f72a77fff1793c7325d5 (diff)
downloadOneRoll-615a7e3e5d8c85ef0eedbff4fa3a29ebeded92cd.tar.gz
OneRoll-615a7e3e5d8c85ef0eedbff4fa3a29ebeded92cd.zip
coding style on sort result node.
Diffstat (limited to 'node/sortresult.cpp')
-rw-r--r--node/sortresult.cpp114
1 files changed, 55 insertions, 59 deletions
diff --git a/node/sortresult.cpp b/node/sortresult.cpp
index 274c61a..f22107d 100644
--- a/node/sortresult.cpp
+++ b/node/sortresult.cpp
@@ -38,82 +38,78 @@ void SortResultNode::run(ExecutionNode* node)
}
DiceResult* previousDiceResult= dynamic_cast<DiceResult*>(node->getResult());
m_diceResult->setPrevious(previousDiceResult);
- if(nullptr != previousDiceResult)
- {
- auto const& diceList= previousDiceResult->getResultList();
- QList<Die*> diceList2= m_diceResult->getResultList();
+ if(nullptr == previousDiceResult)
+ return;
- /* const auto& asce = [](const Die* a,const Die* b){
- return a->getValue() < b->getValue();
- };
- const auto& desc = [](const Die* a,const Die* b){
- return a->getValue() > b->getValue();
- };
+ auto const& diceList= previousDiceResult->getResultList();
+ QList<Die*> diceList2= m_diceResult->getResultList();
- for(auto const dice : diceList)
- {
- Die* tmp1 = new Die(*dice);
- diceList2.append(tmp1);
- }
- if(m_ascending)
- std::sort(diceList2.begin(), diceList2.end(), asce);
- else
- std::sort(diceList2.begin(), diceList2.end(), desc);*/
+ /* const auto& asce = [](const Die* a,const Die* b){
+ return a->getValue() < b->getValue();
+ };
+ const auto& desc = [](const Die* a,const Die* b){
+ return a->getValue() > b->getValue();
+ };
- // half-interval search sorting
- for(int i= 0; i < diceList.size(); ++i)
- {
- Die* tmp1= new Die(*diceList[i]);
- //*tmp1=*diceList[i];
- diceList[i]->displayed();
+ for(auto const dice : diceList)
+ {
+ Die* tmp1 = new Die(*dice);
+ diceList2.append(tmp1);
+ }
+ if(m_ascending)
+ std::sort(diceList2.begin(), diceList2.end(), asce);
+ else
+ std::sort(diceList2.begin(), diceList2.end(), desc);*/
+
+ // half-interval search sorting
+ for(int i= 0; i < diceList.size(); ++i)
+ {
+ Die* tmp1= new Die(*diceList[i]);
+ qDebug() << tmp1->getColor() << diceList[i]->getColor();
+ //*tmp1=*diceList[i];
+ diceList[i]->displayed();
- int j= 0;
- bool found= false;
- int start= 0;
- int end= diceList2.size();
- Die* tmp2= nullptr;
- while(!found)
+ int j= 0;
+ bool found= false;
+ int start= 0;
+ int end= diceList2.size();
+ Die* tmp2= nullptr;
+ while(!found)
+ {
+ int distance= end - start;
+ j= (start + end) / 2;
+ if(distance == 0)
+ {
+ j= end;
+ found= true;
+ }
+ else
{
- int distance= end - start;
- j= (start + end) / 2;
- if(distance == 0)
+ tmp2= diceList2[j];
+ if(tmp1->getValue() < tmp2->getValue())
{
- j= end;
- found= true;
+ end= j;
}
else
{
- tmp2= diceList2[j];
- if(tmp1->getValue() < tmp2->getValue())
- {
- end= j;
- }
- else
- {
- start= j + 1;
- }
+ start= j + 1;
}
}
- diceList2.insert(j, tmp1);
}
+ diceList2.insert(j, tmp1);
+ }
- if(!m_ascending)
- {
- for(int i= 0; i < diceList2.size() / 2; ++i)
- {
- diceList2.swapItemsAt(i, diceList2.size() - (1 + i));
- }
- }
- m_diceResult->setResultList(diceList2);
- if(nullptr != m_nextNode)
+ if(!m_ascending)
+ {
+ for(int i= 0; i < diceList2.size() / 2; ++i)
{
- m_nextNode->run(this);
+ diceList2.swapItemsAt(i, diceList2.size() - (1 + i));
}
}
- else
+ m_diceResult->setResultList(diceList2);
+ if(nullptr != m_nextNode)
{
- // m_result = node->getResult();
- // m_errors.append(DIE_RESULT_EXPECTED);
+ m_nextNode->run(this);
}
}
void SortResultNode::setSortAscending(bool asc)