I am supposed to build my own swap function for my class. It runs, but it doesn't produce the correct output. I would greatly appreciate any help or advice on what I am doing wrong. Thanks in advance for your time!
int main()
{
//code before...
List newa;
for (int i=1;i<=20;i++)
newa.insertAfter(i*3);
cout << "List alist and newa before swap " << endl;
cout << " " << alist << endl;
cout << " " << newa << endl;
//Swap the two lists
alist.swap(newa);
cout << "List alist and newa after swap " << endl;
cout << " " << alist << endl;
cout << " " << newa << endl;
//more code follows...
//Exit program
return EXIT_SUCCESS;
}
//Function to swap the two lists
void List::swap(List CurrentList)
{
// Create temporary holder
List temp;
// Populate temp list with current list
for (int i = 0; i < CAPACITY; i++)
{
temp.MyAry[i]= CurrentList.MyAry[i];
}
// Replace current list with other list
for (int i = 0; i < CAPACITY; i++)
{
CurrentList.MyAry[i] = MyAry[i];
}
// Replace second list with temp list
for (int i = 0; i < CAPACITY; i++)
{
MyAry[i] = temp.MyAry[i];
}
}