Professional Documents
Culture Documents
Recursive Practice Questions
Recursive Practice Questions
if(n>0)
return n%2*pow(10,d)+DtoB(n/2,d+1);
}else
return 0;
if(l>u)
return;
else{
printArrayReverse(a,l+1,u);
cout<<a[l]<<" ";
if(u<l)
return;
else
cout<<a[u]<<" ";
printArrayReverse0(a,l,u-1);
if(l>u)
return;
else{
cout<<a[u]<<" ";
printArrayReverse1(a,l,u-1);
if(size==0)
return;
else{
cout<<a[size-1]<<" ";
printArrayReverse2(a,size-1);
void printArrayReverse3()
if(size==0)
return;
else{
cout<<a[--size]<<" ";
printArrayReverse3();
Rewrite the destroy member function of the class linkedListType using recursion.
template < class Type >
void linkedListType < Type > ::destroyList() {
if (first != NULL) //while there are nodes in the list
{
nodeType <Type> *temp = first; //set temp to the current node
first = first->link; //advance this->first to the next node
delete temp; //deallocate the memory occupied by temp
destroyList();
}else{
last = NULL; //initialize this->last to NULL; this->first has already
//been set to NULL by the while loop
this->count = 0;
}
}