- implemented swap in schedulable_list.cc

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@390 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
fpaparel 2006-02-22 23:19:51 +00:00
parent 73a3e72118
commit b7f3086286
1 changed files with 56 additions and 20 deletions

View File

@ -200,3 +200,39 @@ SchedulableList::has_same_objects(const SchedulableList& dx) const
return true;
}
void
SchedulableList::swap(unsigned int positionA, unsigned int positionB) throw()
{
if (positionA == positionB || positionA >= _list.size() || positionB >= _list.size())
return;
unsigned int min, max;
if (positionA < positionB)
{
min = positionA;
max = positionB;
}
else
{
min = positionB;
max = positionA;
}
list<SchedulableStatus>::iterator i1 = _list.begin();
list<SchedulableStatus>::iterator i2 = _list.begin();
//reach the first element;
for (uint f=0; f < min; f++)
i1++;
SchedulableStatus temp = *i1;
//reach the second element;
i2 = i1;
for (uint f=min; f < max; f++)
i2++;
*i1 = *i2;
*i2 = temp;
}