原创 C++中 public,protected, private 訪問標號
第一:private, public, protected 訪問標號的訪問範圍。 private:只能由1.該類中的函數、2.其友元函數訪問。 不能被任何其他訪問,該類的對象也不能訪問。 protected:可以被1.該類中的函數、2.子
原创 [LeeCode] Insertion Sort List
Question: Sort a linked list using insertion sort. Solution: /** * Definition for singly-linked list. * struct ListNo
原创 中綴表達式轉後綴表達式算法及實現—棧的應用
我們在數學中常見的計算式,例如2+(3*4)叫做中綴表達式。表達式中涉及到了多個運算符,而運算符之間是有優先級的。計算機在計算並且處理這種表達式時,需要將中綴表達式轉換成後綴表達式,然後再進行計算。 中綴表達式:0.3/(5*
原创 [LeetCode] Generate Parentheses
Question: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Fo
原创 [LeetCode] Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NU
原创 尋找兩個相交鏈表的第一個公共節點
Q:已知有兩個鏈表,他們可能相交於某一點,求出該點。 方法1. 最簡單的方法就是先順序訪問其中一個鏈表,在每訪問一個節點時,都對另外一個鏈表進行遍歷,看節點是否相等 直到找到一個相等的節點位置,如果鏈表長度分別是m,n 則時間複雜度爲
原创 [LeetCode]判斷迴文數(Palindrome Number)
題目來源:Leetcode(www.leetcode.com) Question: Determine whether an integer is a palindrome. Do this without extra space.
原创 檢驗某符號(如圓括號,方括號,花括號等)是否都成對出現
檢驗某個符號(如圓括號,方括號,花括號等)是否都成對出現。如,[()]是合法的,但[(])是非法的。 這個算法的最簡單方式是用棧實現,具體思路如下: 做一個空棧。讀入字符至文件尾。 如果字符是一個開放符號,則將其壓入棧中。如果字符是一個
原创 The number of nodes within k-hops in a n-D Torus
Torus is a widely used interconnection in high-performance computing systems. Torus can be built as 1D, 2D, 3D, 4D, 5D
原创 一道關於signed和unsigned的微軟面試題
題目: unsigned int i = 3; cout << i * -1; 問輸出結果是多少? 我覺得大部分人的第一反應是-3。但是結果卻不是這樣的,寫了個程序,運行了一下,輸出結果是:4294967293。很詭異的一個數字,爲
原创 有一億個隨機數,不排序如何找出其中位數
題目:10G 個整數,亂序排列,要求找出中位數。內存限制爲 2G。只寫出思路即可(內存限制爲 2G的意思就是,可以使用2G的空間來運行程序,而不考慮這臺機器上的其他軟件的佔用內存)。 關於中位數:數據排序後,位置在最中間的數值。即
原创 Reverse a string and reverse a sentence
/* *Function: Reverse a sentence according to the certain delimitation. *Author: Tim *Date: 2013-10-25 */ #include
原创 The problem of Money Changes
/* * Input: n: the money you want to change; unit: starts with the maximum change's unit, e.g. 50 (if there are chan
原创 AVL樹的插入和刪除
1. 概述 AVL樹是最早提出的自平衡二叉樹,在AVL樹中任何節點的兩個子樹的高度最大差別爲一,所以它也被稱爲高度平衡樹。AVL樹得名於它的發明者G.M. Adelson-Velsky和E.M. Landis。AVL樹種查找、插入和刪
原创 排序算法總結
首先先總結一下不穩定排序算法,包括:快速排序,希爾排序,簡單選擇排序,堆排序。 記憶口訣:學習真痛苦,“快” “希” “選” 一 “堆” MM來聊天吧:D 其餘的爲穩定排序。 一、冒泡排序 基本思想是:兩兩比較相鄰記錄的關鍵字,如果反序