You almost have it. I added a couple lines of code for diagnostic purposes and they showed clearly what was going on. Here's the code I added :
node * k_reverse (node * head , int k ){
if(head == NULL){
return NULL ;
}
int j = 1 ;
node * h1 = head ;
node * t1 = head ;
while(j<k){
if(t1->n_adress == NULL){
break ;
}
t1 = t1->n_adress ;
j++ ;
}
node * h2 = t1->n_adress ;
t1->n_adress = NULL ;
both smallans = reversing(h1) ;
cout << "after reversing" << endl; print( smallans.head );
node * so = k_reverse(h2 , k) ;
smallans.tail->n_adress = h2 ;
return smallans.head ;
}
I also moved the print function to be above this one and it gave this output :
1 2 3 4 5 6 7
after reversing
3 2 1
after reversing
6 5 4
after reversing
7
It became clear that the lists were not spliced together correctly. I changed exactly one line and everything worked. Here's that line :
smallans.tail->n_adress = so;