資源描述:
《c++ 經(jīng)典算法 面試絕殺》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、C++經(jīng)典算法面試絕殺分類:?C++2012-09-1222:51?2657人閱讀?評論(0)?收藏?舉報c++面試mergetree算法buildhttp://blog.csdn.net/boylinux/article/details/79730301.鏈表逆序2.鏈表合并3.一棵樹是否某條路徑結(jié)點之和等于給定值。并描述算法復(fù)雜度4.你熟悉的排序算法并描述算法復(fù)雜度。????????快速排序????????歸并排序????????堆排序????????選擇排序????????插入排序??????冒泡排序???????折半插入排序
2、以下代碼都能成功通過。1.鏈表逆序[cpp]?viewplaincopy1.#include???2.using?namespace?std;??3.??4.struct?node??5.{??6.????int?value;??7.????node?*?next;??8.};??9.??10.node*?make_link(void);??11.node*?reverse(node*);??12.void?display(node?*);??13.??14.int?main()??15.{??141.????n
3、ode?*head=make_link();??2.????display(head);??3.????head=reverse(head);??4.????display(head);??5.??6.????return?0;??7.}??8.??9.node*?make_link(void)??10.{??11.????node?*head=new?node();??12.????node?*cur=head;??13.????for(int?i=0;i<10;i++)??14.????{??15.????????cur->va
4、lue=rand()%10;??16.????????cur->next=new?node();??17.????????cur=cur->next;??18.????}??19.??20.????return?head;??21.}??22.??23.node*?reverse(node?*head)??24.{??25.????node?*pre,*post,*cur;??26.????if(!head?&&?!head->next)??27.????????return?head;??28.????pre=head;??29.
5、????cur=pre->next;??30.????while(cur)??31.????{??32.????????post=cur->next;??33.????????cur->next=pre;??34.????????pre=cur;??35.????????cur=post;??36.????}??37.????head->next=NULL;??38.????return?pre;??39.}??40.??41.void?display(node?*?head)??42.{??43.????node?*?cur=he
6、ad;??44.????while(cur)??45.????{??46.????????cout<value<<"?";??47.????????cur=cur->next;??48.????}??141.????cout<??2.??3.using?namespace?std;??4.??5.struct?node??6.{??7.????int?value;??8.????node?*next;??
7、9.};??10.??11.node?*make_list(void);??12.void?display(node?*);??13.void?sort(node?*);??14.node?*merge(node?*,node?*);??15.??16.int?main()??17.{??18.????node?*node1=make_list();??19.????display(node1);??20.????sort(node1);??21.??22.????node?*node2=make_list();??23.????d
8、isplay(node2);??24.????sort(node2);??25.??26.????node?*mnode=merge(node1,node2);??27.?????display(mnode);??28.??29.??