那个copy random pointer linklist的, 大家看看对不对啊?O(3N)~~ O(N)吧 /* A contain data, next pointer, and random pointer, copy the A structure in B */ struct node{ int data; struct node* next; struct node* random; node(int value, node* n, node* r){ data = value; next = n; random = r; } }*llist; void copyrandompointerlist(llist src, llist& dst){ // assume the first node doesn't use. // src is the head pointer of A, assert(src != NULL); llist src_index, dst_index, temp; src_in
build a hashtable for alphabet, keep the current largest one for comparison.
c*e
33 楼
I do not feel your code is right. Of course, my idea may be different from yours. The approach is to create a list of A1->B1->A2->B2->... in the first while loop. In the 2nd while loop, set the randon pointer right. In the 3rd while loop, separate the two lists's by resetting next pointer. What is your approach? Alternatively, why not write a main() and test your code?
in
【在 s****t 的大作中提到】 : 那个copy random pointer linklist的, 大家看看对不对啊?O(3N)~~ O(N)吧 : /* : A contain data, next pointer, and random pointer, copy the A structure in : B : */ : struct node{ : int data; : struct node* next; : struct node* random; : node(int value, node* n, node* r){