Title: Enter two incrementally sorted lists, merge the two linked lists, and make the nodes in the new list still incrementing.
For example:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/2F/wKiom1gKMKzCGbbCAAA1-4c1Xrg589.jpg "title=" 20161021230805.jpg "alt=" Wkiom1gkmkzcgbbcaaa1-4c1xrg589.jpg "/>
/* Merge two sorted list *//* the linked list node is defined as follows: struct Listnode{int _data; Listnode* _next;}; */listnode* mergelist (listnode* pHead1, listnode* pHead2) {if (PHead1 = = NULL)//list 1 is empty linked list {return pHead2;} else if (pHead2 = = null)//List 2 is empty linked list {return pHead1;} else//list 1, 2 are not empty list {listnode* Pmergehead = null;//recursion, treat the remaining list as a sub-problem//Find the node with the smaller value as the Pmergehead chain to the previous layer Pmergehead->_next on if ( Phead1->_data < Phead2->_data) {Pmergehead = Phead1;pmergehead->_next = Mergelist (PHead1->_next, pHead2 );} Else{pmergehead = Phead2;pmergehead->_next = Mergelist (PHead1, phead2->_next);} return pmergehead;}}
This article is from the "zgw285763054" blog, make sure to keep this source http://zgw285763054.blog.51cto.com/11591804/1864429
Interview title: Merging two sorted lists