struct cnode
{
int info;
struct cnode *next;
struct cnode *previous;
};
typedef struct cnode cnode;
pre-made DOUBLY LINKED LIST: 1<->2<->3<->4<->5<->6<->7
So I'm trying to make a recursive function that grabs the mid of the doubly linked list (root = 4) and convert it into a the remaining into a binary tree. I'm still new to recursion so an explanation along with code would be GREATLY appreciated!
EX. 4
/ \
2 6
/ \ / \
1 3 5 7
This is the code I have thus far (which isn't much due to difficulties with recursion)
void *convert(cnode *head){
if(head == NULL)
return;
int count = 0;
cnode *tempHead = head;
while(tempHead != NULL){
count++;
tempHead = tempHead->next;
}
int move = (count/2) + (count%2);
int i;
for(i=1; i<move; i++){
head = head->next;
}
}
Pretty much just sets the head pointer to the mid info (4)