原创 C/C++中的字符串問題
#include <iostream> using namespace std; int main() { char p[8]="abcdefg"; cout << *p << endl; //a cout
原创 大數據量,海量數據 處理方法總結
轉自:http://www.cppblog.com/longzxr/archive/2010/10/24/131047.aspx?opt=admin 大數據量的問題是很多面試筆試中經常出現的問題,比如baidu google 騰訊 這
原创 給定一個數組和一個數M,在數組中求一些數使它們的和最接近M------用遞歸法實現的。。。。。。
#include <iostream> #include <math.h> using namespace std; /*數組從a[from]到a[to],b[i]=true表示a[i]被選到,假設選到的那些數和爲sum, 函數
原创 前++ 後++
int b = (++a) * (a++); 等價於 int b = (a++) * (++a); 可解釋爲 : ++a; int b = a * a; a++; int b
原创 模板swap
template <typename tp,size_t num> void swap(tp (&a)[num], tp (&b)[num]) { for(size_t t=0; t<num; ++t) swap(
原创 歸併排序
#include <iostream> #include <assert.h> using namespace std; void myMerge(int a[], int from, int mid, int to) { a
原创 lenovo G510裝win7 + ubuntu雙系統
因爲先裝了win7是在EFI模式下,所以裝ubuntu也要選擇EFI模式下裝。裝好後可以進入ubuntu用boot-repair修改MBR,同時在BIOS下調整EFI下的啓動順序,將ubuntu設爲第一順序。這樣就可以用ubuntu引導w
原创 深拷貝 和 淺拷貝
深拷貝和淺拷貝的定義可以簡單理解成:如果一個類擁有資源(堆,或者是其它系統資源),當這個類的對象發生複製過程的時候,這個過程就可以叫做深拷貝,反之對象存在資源,但複製過程並未複製資源的情況視爲淺拷貝 淺拷貝資源後在釋放資源的時候會產生資
原创 二分查找
int binarySearch(int a[], int startIndex, int endIndex, const int target) { int left = startIndex; int right =
原创 高效刪除vector中的負數
採用交換的方法,減少元素移動次數 void eraseNegative(vector<int>& vect) { vector<int>::iterator iter = vect.begin(); for(; iter
原创 一些C++語法
一、 C++ 中cast 意爲強制類型轉換 , const_cast 去除const特性; static_cast 類型靜態轉換 float f; static_cast<int>(f);
原创 淺析動態內存分配及Malloc/free的實現
注意:C/C++操作符 malloc , new 申請到的是進程虛擬地址空間。 一、概述: 動態內存分配,特別是開發者經常接觸的Malloc/Free接口的實現,對許多開發者來說,是一個永遠的話題,而且有時候也是一個比較迷
原创 copy_constructor, copy_assignment
#include <iostream> using namespace std; class Base { public: Base() { cout << "Base constructor " <<
原创 在數組中刪除儘可能少的數,使得數組滿足“先由小到大,再由大到小”
void MyDelete(int* a, int n) { int* asc = new int[n]; // asc[i]表示以a[i]結尾的最長升序數的個數 int* desc = new int[n];
原创 effective c++
1. 不要讓構造函數和析構函數吐出異常, 這樣可能會造成資源泄漏和不明確行爲 2.構造函數和析構函數不要調用虛函數。 3.將基類析構函數定義爲虛函數 ,這樣動態析構時不會出錯 4.將常用精簡的函數設爲inline,不要濫用,否則造成代碼膨