带头结点的单链表简单选择排序(一个带头结点的单链表)
typedef struct ListNode{ListNode *next;Element data;}ListNode, *pList;这是我做的单链表逆序三个不同的算法。
2个递归的以及一个非递归的pList ReverseList( pList head ){if( !head || !(head->next) )return head;pList ph = ReverseList( head->next );head->next->next = head;head->next = NULL;return ph;}pList ReverseList( pList head , pList &tail ){if( !head || !(head->next) ){tail = head;return head;}pList pt;pList ph = ReverseList( head->next , pt );pt->next = head;head->next = NULL;tail = head;return ph;}pList ReverseListNonRec( pList head ){if( !head || !(head->next) )return head;pList h = NULL,h1 = head;while( head ){h1 = head->next;head->next = h;h = head;head = h1;}return h;}。