編寫代碼,以給定值x爲基準將鏈表分割成兩部分,全部小於x的結點排在大於或等於x的結點以前

問題分析: 這道題的作法是遍歷鏈表,發現比該數小的數使用尾插法插入一個鏈表,大的數再插入一個鏈表,最後再把兩個鏈表鏈接在一塊兒而且把最後一個結點的next置爲空。web public static Node partition(Node head,int x) { Node small=null; Node big=null; Node smallLast=null
相關文章
相關標籤/搜索