void alternatingsplitinrev(struct node* src, struct node** aref, struct node** bref) { struct node* a = NULL; struct node* b = NULL; struct node* cur = src; while(cur != NULL) { movenode(&cur, &a); if(cur != NULL) movenode(&cur, &b); } *aref = a; *bref = b; }
void testmovenode() { struct node* node = NULL; node = buildlistinsortedorder(5); printlist(node, "node"); struct node* temp = buildlistinsortedorder(5); printlist(temp, "temp"); movenode(&node, &temp); printlist(node, "node"); printlist(temp, "temp"); }
void alternatingsplit(struct node* src, struct node** aref, struct node** bref) { struct node dummya; dummya.next = NULL; struct node* a = &dummya; struct node dummyb; dummyb.next = NULL; struct node* b = &dummyb; struct node* cur = src; while(cur != NULL) { movenode(&cur, &(a->next)); a = a->next; if(cur != NULL) { movenode(&cur, &(b->next)); b = b->next; } } *aref = dummya.next; *bref = dummyb.next; }
main() { struct node *a = NULL; struct node *b =NULL; push(&a,2); push(&a,1); push(&b,4); push(&b,3); // printf("%d\n",a->n); print(a); print(b); movenode(&a,&b); print(a); print(b); }