摘要:今天發(fā)現(xiàn)自己對于數(shù)據(jù)結(jié)構(gòu)有點陌生了,最近幾年主要精力放在語言層次上,這些基本的東西反而有些陌生了,溫故而知新,決定花些時間把這些東西整理下。本文不定期更新。
今天發(fā)現(xiàn)自己對于數(shù)據(jù)結(jié)構(gòu)有點陌生了,最近幾年主要精力放在語言層次上,這些基本的東西反而有些陌生了,溫故而知新,決定花些時間把這些東西整理下。本文不定期更新。
- 樹的層次遍歷
輸入
4 / 6 9 / 7 8 12
要求打印出 4->6->9->7->8->12
public void PrintByLevel() { LinkedListl = new LinkedList (); l.add(this); while (!l.isEmpty()) { Tree tmp = l.pollFirst(); System.out.println(tmp.getValue()); if (null != tmp.getLChild()) { l.add(tmp.getLChild()); } if (null != tmp.getRChild()) { l.add(tmp.getRChild()); } } }
鏈表的遞歸和非遞歸反轉(zhuǎn)
遞歸反轉(zhuǎn)
// 遞歸,在反轉(zhuǎn)當前節(jié)點之前先反轉(zhuǎn)后續(xù)節(jié)點
public static ListNode Reverse(ListNode head) { if (null == head || null == head.next) { return head; } ListNode reversedHead = Reverse(head.next); head.next.next = head; head.next = null; return reversedHead; }
非遞歸反轉(zhuǎn)
public static ListNode NoneRecursiveReverse(ListNode head) { ListNode retval = null; ListNode node = head; ListNode preNode = null; while ( node != null ){ // get the next node, and save it at pNext ListNode nextNode = node.next; // if the next node is null, the current is the end of original // list, and it"s the head of the reversed list if ( nextNode == null) { retval = node; } // reverse the linkage between nodes node.next = preNode; preNode = node; node = nextNode; } return retval; }
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/64289.html
摘要:回顧選擇排序,插入排序,冒泡排序,快速排序,希爾排序,歸并排序,堆排序以及如何計算時間復雜度學習文章同學的描述數(shù)據(jù)結(jié)構(gòu)等同學的十大經(jīng)典算法本文代碼也上傳到了排序算法回顧。但希爾排序是非穩(wěn)定排序算法。 回顧選擇排序,插入排序,冒泡排序,快速排序,希爾排序,歸并排序,堆排序以及如何計算時間復雜度學習文章:hahda同學的javascript描述數(shù)據(jù)結(jié)構(gòu)、hustcc等同學的十大經(jīng)典算法 ...
摘要:社區(qū)投稿配置解析投稿余朝飛本文簡單介紹了中的三個重要的配置段落,分別是的系統(tǒng)配置,用戶配置以及黑白名單功能,針對用戶配置則介紹了實際應用場景下的配置以及對應的權(quán)限配置,并詳細介紹了黑白名單配置實踐。 1月24日,我們發(fā)布了為期30天的「如何獲取全國 25場 MySQL 主題大會免費入場券」有獎社區(qū)分享活動,希望社區(qū)同學能夠分享測試或生產(chǎn)環(huán)境中DBLE使用上的難題,困惑,創(chuàng)新或收獲,分享...
閱讀 1503·2023-04-25 15:40
閱讀 2891·2021-08-11 11:15
閱讀 2289·2019-08-26 13:48
閱讀 2861·2019-08-26 12:18
閱讀 2464·2019-08-23 18:23
閱讀 2918·2019-08-23 17:01
閱讀 2992·2019-08-23 16:29
閱讀 1111·2019-08-23 15:15