1->链表的翻转
typedef struct List{ int val; List * next; }LinkList; reverse(LinkList *head) { LinkList *temp = head->next; LinkList *pre = head; LinkList *next = head ->next->next; for(next != NULL) { temp ->next = pre; pre = temp; temp = next; next = next->next; } temp ->next = pre; return temp; }
2->链表找中间节点
typedef struct node_t{ int value; node_t *next; }*LinkList; void middle_node(LinkList * head){ LinkList doubleStep = head; LinkList step = head; while(doubleStep != NULL) { doubleStep = doubleStep->next->next; step = step ->next; } return step; }