Changed the remove() function in tsSLList class because users were
confused by it. The name is now removeNextItem() and it is now a private member of class tsSLNode.
This commit is contained in:
@@ -34,11 +34,13 @@ int main ()
|
||||
list.add(*pFred);
|
||||
list.add(*pFredII);
|
||||
{
|
||||
tsSLIter<fred> iter(list);
|
||||
tsSLIterRm<fred> iter(list);
|
||||
pFredBack = iter();
|
||||
assert(pFredBack == pFredII);
|
||||
pFredBack = iter();
|
||||
assert(pFredBack == pFred);
|
||||
iter.remove(); // removes pFred
|
||||
}
|
||||
list.remove(*pFredII); // removes *pFred !!
|
||||
list.add(*pFred);
|
||||
pFredBack = list.get();
|
||||
assert (pFredBack == pFred);
|
||||
|
||||
+18
-16
@@ -31,6 +31,9 @@
|
||||
*
|
||||
* History
|
||||
* $Log$
|
||||
* Revision 1.14 1998/10/23 16:40:47 jhill
|
||||
* fixed missing new line at EOF
|
||||
*
|
||||
* Revision 1.13 1998/10/23 00:20:41 jhill
|
||||
* attempted to clean up HP-UX warnings
|
||||
*
|
||||
@@ -105,6 +108,20 @@ public:
|
||||
|
||||
private:
|
||||
T *pNext;
|
||||
|
||||
//
|
||||
// removeNextItem ()
|
||||
//
|
||||
// removes the item after this node
|
||||
//
|
||||
void removeNextItem ()
|
||||
{
|
||||
T *pItem = this->pNext;
|
||||
if (pItem) {
|
||||
tsSLNode<T> *pNode = pItem;
|
||||
this->pNext = pNode->pNext;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -136,21 +153,6 @@ public:
|
||||
this->insert (item, *this);
|
||||
}
|
||||
|
||||
//
|
||||
// remove ()
|
||||
// **** removes item after "itemBefore" ****
|
||||
// (itemBefore might be the list header object and therefore
|
||||
// will not always be of type T)
|
||||
//
|
||||
void remove (tsSLNode<T> &itemBefore)
|
||||
{
|
||||
T *pItem = itemBefore.pNext;
|
||||
if (pItem) {
|
||||
tsSLNode<T> *pNode = pItem;
|
||||
itemBefore.pNext = pNode->pNext;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// get ()
|
||||
//
|
||||
@@ -158,7 +160,7 @@ public:
|
||||
{
|
||||
tsSLNode<T> *pThisNode = this;
|
||||
T *pItem = pThisNode->pNext;
|
||||
this->remove(*this);
|
||||
pThisNode->removeNextItem();
|
||||
return pItem;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,13 @@ int main ()
|
||||
list.add(*pFred);
|
||||
list.add(*pFredII);
|
||||
{
|
||||
tsSLIter<fred> iter(list);
|
||||
tsSLIterRm<fred> iter(list);
|
||||
pFredBack = iter();
|
||||
assert(pFredBack == pFredII);
|
||||
pFredBack = iter();
|
||||
assert(pFredBack == pFred);
|
||||
iter.remove(); // removes pFred
|
||||
}
|
||||
list.remove(*pFredII); // removes *pFred !!
|
||||
list.add(*pFred);
|
||||
pFredBack = list.get();
|
||||
assert (pFredBack == pFred);
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
*
|
||||
* History
|
||||
* $Log$
|
||||
* Revision 1.14 1998/10/23 16:40:47 jhill
|
||||
* fixed missing new line at EOF
|
||||
*
|
||||
* Revision 1.13 1998/10/23 00:20:41 jhill
|
||||
* attempted to clean up HP-UX warnings
|
||||
*
|
||||
@@ -105,6 +108,20 @@ public:
|
||||
|
||||
private:
|
||||
T *pNext;
|
||||
|
||||
//
|
||||
// removeNextItem ()
|
||||
//
|
||||
// removes the item after this node
|
||||
//
|
||||
void removeNextItem ()
|
||||
{
|
||||
T *pItem = this->pNext;
|
||||
if (pItem) {
|
||||
tsSLNode<T> *pNode = pItem;
|
||||
this->pNext = pNode->pNext;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -136,21 +153,6 @@ public:
|
||||
this->insert (item, *this);
|
||||
}
|
||||
|
||||
//
|
||||
// remove ()
|
||||
// **** removes item after "itemBefore" ****
|
||||
// (itemBefore might be the list header object and therefore
|
||||
// will not always be of type T)
|
||||
//
|
||||
void remove (tsSLNode<T> &itemBefore)
|
||||
{
|
||||
T *pItem = itemBefore.pNext;
|
||||
if (pItem) {
|
||||
tsSLNode<T> *pNode = pItem;
|
||||
itemBefore.pNext = pNode->pNext;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// get ()
|
||||
//
|
||||
@@ -158,7 +160,7 @@ public:
|
||||
{
|
||||
tsSLNode<T> *pThisNode = this;
|
||||
T *pItem = pThisNode->pNext;
|
||||
this->remove(*this);
|
||||
pThisNode->removeNextItem();
|
||||
return pItem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user