Commit 154eea44 authored by laurence's avatar laurence
Browse files

BUG: mantis #157: swapUp/swapDown changed when considering first/last element

parent 6687dd1c
......@@ -65,30 +65,36 @@ int main(int argc, char *argv[])
}
myList.append(500.3);
myList.append(200.3);
myList.append(100.3);
Info<< nl << "And again using STL const_iterator: " << nl << endl;
const DLList<scalar>& const_myList = myList;
forAllConstIter(DLList<scalar>, const_myList, iter)
forAllConstIter(DLList<scalar>, myList, iter)
{
Info<< "element:" << *iter << endl;
}
Info<< nl << "Testing swapUp and swapDown: " << endl;
Info<< nl << "swapUp" << endl;
myList.swapUp(myList.DLListBase::first());
myList.swapUp(myList.DLListBase::last());
forAllConstIter(DLList<scalar>, const_myList, iter)
forAllIter(DLList<scalar>, myList, iter)
{
Info<< "element:" << *iter << endl;
}
Info<< nl << "swapDown" << endl;
myList.swapDown(myList.DLListBase::first());
myList.swapDown(myList.DLListBase::last());
forAllConstIter(DLList<scalar>, const_myList, iter)
forAllIter(DLList<scalar>, myList, iter)
{
Info<< "element:" << *iter << endl;
}
......@@ -103,8 +109,8 @@ int main(int argc, char *argv[])
Info<< nl << "source: " << myList << nl
<< nl << "target: " << newList << endl;
Info<< nl << "Done." << endl;
return 0;
}
......
......@@ -94,23 +94,23 @@ bool Foam::DLListBase::swapUp(DLListBase::link* a)
if (ap == first_)
{
first_ = a;
ap->prev_ = a;
}
else
{
ap->prev_->next_ = a;
}
if (a == last_)
{
last_ = ap;
a->next_ = ap;
}
if (a->next_)
else
{
a->next_->prev_ = ap;
}
if (ap->prev_)
{
ap->prev_->next_ = a;
}
a->prev_ = ap->prev_;
ap->prev_ = a;
......@@ -135,19 +135,19 @@ bool Foam::DLListBase::swapDown(DLListBase::link* a)
if (a == first_)
{
first_ = an;
a->prev_ = an;
}
if (an == last_)
else
{
last_ = a;
a->prev_->next_ = an;
}
if (a->prev_)
if (an == last_)
{
a->prev_->next_ = an;
last_ = a;
an->next_ = a;
}
if (an->next_)
else
{
an->next_->prev_ = a;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment