diff --git a/applications/test/DLList/Test-DLList.C b/applications/test/DLList/Test-DLList.C index 8e76baa6e1133360e2e168abd48b71ce473cb30d..d3703489825c0cae6b42521ad06e93d9da2cb10b 100644 --- a/applications/test/DLList/Test-DLList.C +++ b/applications/test/DLList/Test-DLList.C @@ -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; } diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C index f837ec3e66a1fee4c98e388ad63af32224519e54..95476fd89a7a15f71cf9bd8d6f78596cfcbec95d 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C @@ -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; }