Single-chain table conversion is very familiar, here is just to practice the chain table operation, there are also a few points to note, if it is recursive to solve this problem, if it is adjacent two transpose how to deal.
1. Transpose non-recursion of a single-chain table
Void reverse (struct node ** list) {struct node * currentp = * List; struct node * pleft = NULL; struct node * pright = NULL; while (currentp! = NULL) {pright = currentp-> next; currentp-> next = pleft; pleft = currentp; currentp = pright;} * List = pleft ;}
2. Transpose recursion of a single-chain table
Struct node * recursive_reverse (struct node * List) {struct node * head = List; struct node * P = r_reverse (list); head-> next = NULL; return P ;} struct node * r_reverse (struct node * List) {If (null = List | null = List-> next) return list; struct node * P = r_reverse (list-> next); List-> next = List; return P ;}
3. Transpose Adjacent Elements in a single-link table (non-recursive)
Struct node * recursive_reverse (struct node * List) {struct node * head = List; struct node * P = r_reverse (list); head-> next = NULL; return P ;} struct node * r_reverse (struct node * List) {If (null = List | null = List-> next) return list; struct node * P = r_reverse (list-> next); List-> next = List; return P ;}
4. Transpose (recursion) of Adjacent Elements in a single-chain table)
Struct node * recursive_partial_reverse (struct node * List) {If (null = List | null = List-> next) return list; struct node * P = List-> next; struct node * node = recursive_partial_reverse (list-> next); List-> next = List; List-> next = node; return P ;}