44 Usingthe list ADT of Figure 41 write a function to inter
44 Usingthe list ADT , of Figure 4.1, write a function to interchange the cur element and the one following it.
Solution
below is the function to exchange current element with the subsequent one.
void exchange()
{
int listsz=length(); //retrieving list size
int position = currPos(); //getting current position by calling function currPos;
if position+1 > listSz // checking if current element is last element of list or not.
break;
else
{
E temp=listArray[position]; //code to swap the value at two position
listArray[position]=listArray[position+1];
listArray[position+1]=temp;
}
}
comments are included in code.
any more detailed explanation and correction required please do tell me in comments section.
