题解 | #单链表的排序#
单链表的排序
http://www.nowcoder.com/practice/f23604257af94d939848729b1a5cda08
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * * @param head ListNode类 the head node * @return ListNode类 */ struct ListNode* sortInList(struct ListNode* head ) { // write code here struct ListNode *p1 ,*p2,*p3; int b; for(p1=head;p1!=NULL;p1=p1->next) for(p2=p1;p2!=NULL;p2=p2->next) {if(p1->val>p2->val){ b=p2->val; p2->val=p1->val; p1->val=b;} } return head; }