From A C++ beginner. I have written a class that splits the first list into 2.I used iterators to accomplish it. Now I am supposed to create a new method that splits the input chain ∗this, destroys the input chain and uses its nodes to construct the chains a and b. I am lost.
template <class T>
void chain<T>::Split(chain<T>& A, chain<T>& B, chain<T>& C)
{// Split A into two chains B and C.
// When done, A is unchanged.
// first free all nodes in B and C
int j;
j=0 ;
listSize = B.listSize;
for (j=0 ; j < listSize; j++)
B.erase(0);
// C.Erase();
j=0 ;
listSize = C.listSize;
for (j=0 ; j < listSize; j++)
C.erase(0);
// assign elements alternately to B and C
int n=0;
chain<T>::iterator a = A.begin(); // find first node of A
while (a != A.end()) {
// first give B an element
B.insert(n,*a);
a++;
if (a == A.end()) break;
// now give C an element
C.insert(n,*a);
a++;
n=n+1;
}
}