【100題】二叉樹的鏡像變換

//二叉樹的鏡像變換#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 =

重點在確定字元數組的長度!!防止數組越界

 #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<<"

記憶體大了,但是系統沒覺得快,怎麼最佳化記憶體呢?

根據我的經驗,當記憶體大於1G以後,其實硬碟的虛擬記憶體就是雞肋了。但XP似乎一定要虛擬記憶體,怎麼辦呢?後來我發現使用ramdisk可以比較充分的利用記憶體。只要三步,方法如下: 1、使用ramdisk將實體記憶體的一半,記住,是一半,如果是2G的話,就設定1G的虛擬硬碟。2、然後再系統的虛擬記憶體設定中,將虛擬記憶體設定到這個虛擬硬碟上,一般是R盤,記住不能全部分配,要留10%左右的空間,否則系統會不停的提示硬碟滿。3、取消其他的虛擬記憶體設定,重啟機器。 現在,你可以享受全實體記憶體帶來的

多繼承 類的構造的調用順序

#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" <<

【openCV】多通道的拆分

#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 =

【基礎排序】鳥巢排序

//鳥巢排序#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);

【面試題】strcmp函數實現

#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

【matlab】長條圖均衡化

%一,映像的預先處理,讀入彩色映像將其灰階化 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];

【100題】在排序數組中尋找和為給定值的兩個數

//在排序數組中尋找和為給定值的兩個數#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 >

【面試題】k序數組的排序問題

在網上看到的一道面試題,覺得思路不錯,收藏一下。首先什麼是k序數組呢?具備這樣特徵的數組:其中的第i個元素在排序之後的位置位於[i-k, i+k]之間即稱之為k序的題目要求:試寫演算法把一個k序數組排序. 解法:根據k序數組的特性,顯然有以下幾個子序列:X[0], X[k+1], X[2(k+1)], 

把英文文本中的標點符號用空格替換

 #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>

【STL】sort和copy的用法

#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>

【二叉樹遍曆】先序—非遞迴實現

#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)

【基礎排序】計數排序-簡潔版

#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

【面試題】考察指標和記憶體布局的一個題目

#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的首地址//

OpenCV實現PCA演算法—-輸出異常

#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

【基礎排序】計數排序

//計數排序//適用於維數小,但記錄數龐大的資料集的排序任務//維數小是為了讓輔助數組小,使用的額外空間就小了。//時間複雜度為O(n)//空間複雜度就是輔助數組的長度,也就是維數max(a[i])+1的一個數組//比如:100萬學生的成績,成績範圍為0到720分。非常適合這種排序演算法#include <iostream>#include <time.h>#include <assert.h>using namespace std;void

【二叉樹遍曆】有前序走訪 和 中序遍曆 求 後序遍曆

/*假設前序走訪為 adbgcefh, 中序遍曆為 dgbaechf 前序走訪是先訪問根節點,然後再訪問子樹的,而中序遍曆則先訪問左子樹再訪問根節點 那麼把前序的 a 取出來,然後尋找 a 在中序遍曆中的位置就得到 dgb a echf 那麼我們就知道 dgb 是左子樹 echf 是右子樹,因為數量要吻合 所以前序中相應的 dbg 是左子樹 cefh 是右子樹 然後就變成了一個遞迴的過程*/#include <iostream>#include

【STL】inserter和front_inserter的用法

#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(),

【基礎排序】歸併排序

#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

總頁數: 61357 1 .... 21098 21099 21100 21101 21102 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.