本题要求实现一个函数,将给定单向链表逆置,即表头置为表尾,表尾置为表头。链表结点定义如下:
struct ListNode *reverse( struct ListNode *head ) { struct ListNode *p = head; struct ListNode *newhead = NULL; while(p) { struct ListNode * r = (struct ListNode*)malloc(sizeof( struct ListNode)); r->data = p->data ; r->next = newhead; newhead = r; p = p->next; } return newhead;
标签:ListNode,struct,表头,newhead,链表,逆置 From: https://www.cnblogs.com/fan-wang/p/16823517.html