Time of Update: 2018-12-03
//二叉樹的鏡像變換#include <iostream>#include <stack>using namespace std;//二叉樹結構struct BTreeNode {int m_nValue;BTreeNode *m_pLeft;BTreeNode *m_pRight;};//遞迴實現void MirrorRecursively(BTreeNode *pNode){if(!pNode){return;}//交換左右孩子BTreeNode *pTemp =
Time of Update: 2018-12-03
#include <iostream>#include <string>#include <cstring>using namespace std;int main(){string in_str;size_t str_size = 10;char *result_str =new char[str_size + 1];cout << "enter a string (<="<<str_size<<"
Time of Update: 2018-12-03
根據我的經驗,當記憶體大於1G以後,其實硬碟的虛擬記憶體就是雞肋了。但XP似乎一定要虛擬記憶體,怎麼辦呢?後來我發現使用ramdisk可以比較充分的利用記憶體。只要三步,方法如下: 1、使用ramdisk將實體記憶體的一半,記住,是一半,如果是2G的話,就設定1G的虛擬硬碟。2、然後再系統的虛擬記憶體設定中,將虛擬記憶體設定到這個虛擬硬碟上,一般是R盤,記住不能全部分配,要留10%左右的空間,否則系統會不停的提示硬碟滿。3、取消其他的虛擬記憶體設定,重啟機器。 現在,你可以享受全實體記憶體帶來的
Time of Update: 2018-12-03
#include <iostream>using namespace std;class A{private:int a;public:A(){cout << "A" <<endl;}};class B : public A{private :int b;public:B(){cout << "B" <<endl;}};class C{private:int c;public:C(){cout << "C" <<
Time of Update: 2018-12-03
#include <cv.h>#include <highgui.h>#include <iostream>using namespace std;void main(){IplImage *src = cvLoadImage("H:\\CMU表情庫\\cohn-kanade\\cohn-kanade\\cohn-kanade\\S010\\001\\S010_001_01594226.png",1);IplImage *dst =
Time of Update: 2018-12-03
//鳥巢排序#include <iostream> using namespace std; void pigen_hole_sort(int *array,int length); int main() { int a[] = {4,6,1,8,9,2,3,5,7,0,1,10,19,12,16,14}; int n = sizeof(a)/sizeof(a[0]); pigen_hole_sort(a,n);
Time of Update: 2018-12-03
#include <iostream>#include <assert.h>using namespace std;int strcmp_mf(const char *src,const char *dst){assert(src != NULL && dst != NULL);while(*src++ == *dst++){if(*src=='\0' && *dst=='\0'){return
Time of Update: 2018-12-03
%一,映像的預先處理,讀入彩色映像將其灰階化 dirtest = 'H:\CMU表情庫\cohn-kanade\cohn-kanade\cohn-kanade\S010\003\'; DIRS_test = dir([dirtest,'*.png']); m = 18 %檔案夾內的圖片個數 for w = 1:m if ~DIRS_test(w).isdir string_test = [dirtest,DIRS_test(w).name];
Time of Update: 2018-12-03
//在排序數組中尋找和為給定值的兩個數#include <iostream>using namespace std;bool FindNum(int data[],unsigned int length,int sum,int &n1,int &n2 ){bool found = false;if(length < 1){return found;}int ahead = length - 1;int behind = 0;while(ahead >
Time of Update: 2018-12-03
在網上看到的一道面試題,覺得思路不錯,收藏一下。首先什麼是k序數組呢?具備這樣特徵的數組:其中的第i個元素在排序之後的位置位於[i-k, i+k]之間即稱之為k序的題目要求:試寫演算法把一個k序數組排序. 解法:根據k序數組的特性,顯然有以下幾個子序列:X[0], X[k+1], X[2(k+1)],
Time of Update: 2018-12-03
#include <iostream>#include <string>#include <cctype>#include <fstream>#include <vector>#include <sstream>using namespace std;void main(){fstream inFile;inFile.open("d://infile.txt");vector<string>
Time of Update: 2018-12-03
#include <iostream>#include <time.h> #include <algorithm> #include <vector> using namespace std; void Display(vector<int>& v, const char* s); int main() { srand(time(NULL)); vector<int>
Time of Update: 2018-12-03
#include <iostream>#include <stack>using namespace std;//樹結構struct BTreeNode{int m_nValue;BTreeNode *m_pLeft;BTreeNode *m_Right;};void visit(BTreeNode *n){cout<< n->m_nValue<<" ";}//非遞迴先序遍曆,方法1void PreOrder(BTreeNode *root)
Time of Update: 2018-12-03
#include <iostream>#include <assert.h>#include <time.h>using namespace std;void Sort(int A[], int n){ assert(n > 0);int max = A[0];for(int i=0; i<n; ++i){if(max < A[i]){max = A[i];}} int *C = new int[max+1];memset(C,0
Time of Update: 2018-12-03
#include <iostream>using namespace std;void main(){char data[10];short cOut;for(int i=0;i<10;++i){data[i] = i;}cOut = *(short *)((int *)data+1);cout << cOut <<endl;}//字元數組初始化為:1到10//data指向數組第一個元素的首地址//轉成int * 型指標,移動一個單位,到了4的首地址//
Time of Update: 2018-12-03
#include <cv.h>#include <highgui.h>#include <stdio.h>#include <stdlib.h>#pragma comment(lib,"cv200.lib")#pragma comment(lib,"highgui200.lib")#pragma comment(lib,"cxcore200.lib")double Coordinate[21]={ 1.5,2.3, 3.0,1.7, 1.2,2.9
Time of Update: 2018-12-03
//計數排序//適用於維數小,但記錄數龐大的資料集的排序任務//維數小是為了讓輔助數組小,使用的額外空間就小了。//時間複雜度為O(n)//空間複雜度就是輔助數組的長度,也就是維數max(a[i])+1的一個數組//比如:100萬學生的成績,成績範圍為0到720分。非常適合這種排序演算法#include <iostream>#include <time.h>#include <assert.h>using namespace std;void
Time of Update: 2018-12-03
/*假設前序走訪為 adbgcefh, 中序遍曆為 dgbaechf 前序走訪是先訪問根節點,然後再訪問子樹的,而中序遍曆則先訪問左子樹再訪問根節點 那麼把前序的 a 取出來,然後尋找 a 在中序遍曆中的位置就得到 dgb a echf 那麼我們就知道 dgb 是左子樹 echf 是右子樹,因為數量要吻合 所以前序中相應的 dbg 是左子樹 cefh 是右子樹 然後就變成了一個遞迴的過程*/#include <iostream>#include
Time of Update: 2018-12-03
#include <iostream> #include <algorithm> #include <list> using namespace std; int iArray[5] = { 1, 2, 3, 4, 5 }; void Display(list<int>& a, const char* s) { cout << s << endl; copy(a.begin(),
Time of Update: 2018-12-03
#include <iostream>#include <time.h>using namespace std;void merge_bxy(int *a,int low,int mid,int high){int p;int i=low;int j=mid+1;int k=low;int *temp = new int[high+1];memset(temp,0,sizeof(int)*(high+1));//前一半和後一半進行歸併for(;i<=mid