aidynamic
BAN USERHave not been able to test, but following are my thoughts...
/*
Assumptions on requirements...
input ----- output
NULL ----- NULL
a->NULL ----- a->NULL
a->b->NULL ----- b->a->NULL
a->b->c->NULL ----- b->a->c->NULL
a->b->c->d->NULL ----- b->a->d->c->NULL
*/
Node* recur_modify(Node *p, int &num_nodes) {
++num_nodes;
if (p->next == NULL) return p;
Node *next = recur_modify(p->next, num_nodes);
if (next->next == NULL)
if (num_nodes % 2 != 0) return p;
p->next = next->next;
next->next = p;
return next;
}
void modify(Node *root) {
if (root == NULL) return root;
int num_nodes = 0;
root = recur_modify(root, num_nodes);
}
Should'nt the answer be 206m with path (1, 100, 100, 2, 3) for following..
- aidynamic September 23, 2012{{
{1, 2, 3, 6},
{100, 2, 6, 10},
{100, 2, 3, 3}
}}