原创 LeetCode---Binary Search Tree Iterator ---C++

問題描述: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of

原创 Ugly Number Ugly Number II

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime fact

原创 STL源碼剖析-緒論

STL,標準模板庫,無處不存在GP(generic programming泛型編程),有多種實現版本。 GNU C++採用的STL爲:SGI STL,源碼下載,參考文檔。 STL文件講解一:<stl_config.h> 針對不同的編譯器

原创 二叉樹遍歷(遞歸、非遞歸,層次遍歷(從上往下))

遞歸算法 void preorder1(Node *root) //遞歸前序遍歷 { if (root == NULL) return; printf("%d ", root->val); preorder1(root->lef

原创 leetcode--Find Minimum in Rotated Sorted Array --C++

問題: Find Minimum in Rotated Sorted Array   Suppose a sorted array is rotated at some pivot unknown to you beforehand.

原创 leetcode--Find Minimum in Rotated Sorted Array II ---C++

Find Minimum in Rotated Sorted Array II Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates

原创 leetcode--Lowest Common Ancestor of a Binary Tree --C

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definitio

原创 計算機網絡面試題

1、OSI(Open System Interconnect):開放系統互聯,是一個七層的計算機網絡模型,分別爲:物理層、數據鏈路層、網絡層、傳輸層、會話層、表示層和應用層。 TCP/IP(Transmission Control Pr

原创 STL源碼剖析-型別技術

迭代器(一種泛型指針類型)是容器和算法的膠合劑。在使用中,經常會使用迭代器相關的類型。 來看迭代器類型萃取機。 文件:stl_iterator_base.h 定義迭代器種類的五種類型,這五種類型不包含任何數據,只是用來作爲參數傳遞給算

原创 哈夫曼(huffman)樹和哈夫曼編碼

哈夫曼(huffman)樹和哈夫曼編碼 哈夫曼樹 哈夫曼樹也叫最優二叉樹(哈夫曼樹)    問題:什麼是哈夫曼樹? 例:將學生的百分制成績轉換爲五分製成績:≥90 分: A,80~89分: B,70~79分: C,60~69分:

原创 排序總結

冒泡排序:O(N^2)。輸入對結果沒有影響。 插入排序:最差O(N^2),最優O(N),平均O(N^2)。輸入有影響,例如已排好序,則爲O(N)。 選擇排序:最差,最優,平均都是O(N^2)。輸入對結果沒有影響。 希爾排序:最差爲o(Nl

原创 ‘this’ pointer in C++

this指針作爲一個隱藏的參數傳遞給所有的non-static成員函數,作爲一個局部變量。是一個const-pointer,指向的是當前對象的地址。在static成員函數中沒有this指針,因爲static成員變量不能調用對象內的non-

原创 關鍵字:volatile

volatile用於強制某個實現屏蔽可能的優化。 volatile變量的四個常見示例爲: 爲內存映射 I/O 端口的變量 多個並行進程之間共享的變量 異步信號處理程序修改的變量 調用 setjmp 的函數中聲明的自動存儲持續時間變量

原创 Missing Number

Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is mi

原创 面試題-隨機生成數

題目1:已知rand7()可以產生1~7的7個數(均勻概率),利用rand7() 產 生 rand10() 1~10(均勻概率)。 解答: 產生指定範圍內的隨機數就要求指定範圍內每個數的產生概率都是相等的。 由於無法直接通過rand7