Time of Update: 2018-12-05
Introduction to Algorithms 3rd Edition2.3-7Describe a nlgn-time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements inS whose sum isexactly
Time of Update: 2018-12-05
給定某屬於1-9的正數n,按遞增順序列印出所有排列。如:n=3,則順序列印出123, 132, 213, 231, 312, 321。#include <iostream>using namespace std;struct node{ int value; node *prev; node *next;};void print(const node * const head, node *curr){ if (NULL == curr) {
Time of Update: 2018-12-05
鏈表相鄰元素翻轉,如a->b->c->d->e->f-g,翻轉後變為:b->a->d->c->f->e->gstruct Node{ char value; Node *next;};Node* reverse(Node *head){ if (NULL == head || head->next == NULL) { return head; }
Time of Update: 2018-12-05
給出數字1,2,3.列印出所有可能的排列。如:123, 132, 213, 231...#include <iostream>using namespace std;void print(int a[], int begin, int n){ if (begin == n) { for (int i = 0; i < n; i++) { cout << a[i]; }
Time of Update: 2018-12-05
#include <iostream>#include <stack>using namespace std;struct Node{ int value; Node *left; Node *right;};void postorderTraverse(Node *root){ if (NULL == root) { return; } //p用來記錄最後一次列印的節點 Node *p = root;
Time of Update: 2018-12-05
#include <iostream>#include <queue>using namespace std;struct Node{ int value; Node *left; Node *right;};void printNumOfEveryLevel(Node *root){ if (NULL == root) { return; } queue<Node*>
Time of Update: 2018-12-05
1 編程基礎 1.1 基本概念的理解:const char*, char const*, char*const的區別問題幾乎是C++面試中每次都會有的題目。 事實上這個概念誰都有只是三種聲明方式非常相似很容易記混。 Bjarne在他的The C++ Programming Language裡面給出過一個助記的方法: 把一個聲明從右向左讀。 const char * const cp; ( * 讀成 pointer to ) cp is a const pointer to
Time of Update: 2018-12-05
問題描述:給出2n+1個數 其中有n個數是成對出現的 找出裡面只出現了一次的那個數 當然 如果先快排完了 排除掉相同的數 當然可以找到那個只出現過一次的數 但是快排的複雜度是n*logn
Time of Update: 2018-12-05
比如:原來棧中從頂到底的元素分別為1, 2, 3, 4, 5。.翻轉後棧中從頂到底應分別為5, 4, 3, 2, 1。#include <stack>using namespace std;void addToStack(stack<int> &buf, int value){ if (buf.empty()) { buf.push(value); } else { int
Time of Update: 2018-12-05
一個有序數組(從小到大排列),數組中的資料有正有負,求這個數組中的最小絕對值。int search(int a[], int n){ if (a == NULL) { return -1; } int left = 0; int right = n - 1; while (left < right-1) { int mid = left + (right-left)/2; if (a[mid] == 0)
Time of Update: 2018-12-05
我們知道無論是UDP還是TCP,socket都會與一個本地的IP和連接埠綁定,這個IP和連接埠稱之為socket的源地址和源連接埠。而用戶端利用socket去發送資料時,很少會去考慮這個源地址和源連接埠到底是什麼,我們更關心的是它的目的地址和連接埠。往往只有在伺服器端需要監聽的時候,才去考慮這個源連接埠。所以我們往往在伺服器端監聽的時候才會用bind。當我們bind之後,核心就會將這個socket鎖定到我們設定的地址和連接埠上。事實上,在用戶端也可以先通過bind指定發送資料的連接埠,只是,如果
Time of Update: 2018-12-05
計算兩個字串的最長公用子字串。如"BACABA","ABCBDAB"的最長公用子字串為“BCAB”。若有多個相同長度最長公用子字串,列印其中之一即可。#include <iostream>#include <cstring>using namespace std;int maxCommonSubStr(char *a, int m, char *b, int n){if (m < 1 || n < 1){return 0;} int **len =
Time of Update: 2018-12-05
查閱了好多資料,看了好多東西,感覺VC上的藍芽編程好亂,看得頭都大了,下面把看到的和學到的整理一下(如有錯誤,請指正):VC藍芽編程貌似方式不止一種,網上比較流行的是IVT的BlueSoleil_SDK,用windows上的兩種bluetooth的開放介面,一種是以熟悉的windows sockets方式,另外一種是新加入的BlueTooth APIs方式。在SDK的samples中只提到了windows
Time of Update: 2018-12-05
#include <iostream>using namespace std;struct Node{ int value; Node *next;};Node* merge(Node *left, int leftLen, Node *right, int rightLen){ if (NULL == left || NULL == right) { return NULL; } Node *head = NULL; if (
Time of Update: 2018-12-05
題目:1000瓶水中有一瓶有毒,老鼠喝下有毒水後毒性一周后發作,一周內最少需要多少只老鼠能找出有毒的那瓶水答案:最少需要10隻。思路:將1000瓶水按照二進位從1編號到1000。這樣最大數的二進位位元為10。用10隻老鼠分別對應二進位的第0到第9位,每隻老鼠喝下該二進位位為1的瓶子的水,如果該老鼠一周后死掉,就說明有毒瓶的該二進位位為1,否則說明為0。這樣就能確定有毒瓶的位元。
Time of Update: 2018-12-05
輸入正整數n,要求列印出n*n的蛇形方陣。如n=4時列印如下: 10 11 12 1 9 16 13 2 8 15 14 3 7 6 5 4#include <stdlib.h>#include <stdio.h>#include <string.
Time of Update: 2018-12-05
例題:(1)有如下DFD圖,其中豎虛線輸入、變換、輸出之間的間隔,請將其轉換成SC圖:解:由圖我們可以看出第一豎虛線左邊是輸入部分,中間是變換部分,又邊則是輸出部分。從而我們可以知道一級sc圖除主模組外有四大模組,即輸入模組、輸出模組、變換模組。對於輸入模組我們是通過擷取c,b然後變換後得來的d,對於變換模組我們是通過將d轉換成i和將d轉換成h兩個變換,而輸出模組則可以分別對i和h進行輸出。對接下來的我就不詳細將了,大家可以看下面的SC圖(2).有如下DFD圖轉,其中豎虛線表示輸入、變換、輸出之
Time of Update: 2018-12-05
文章目錄 矩陣解體代碼: 暑假培訓 2011-08-01
Time of Update: 2018-12-05
這是,前面是個原字串,隨機產生,後面是排序後的字串,將大寫字母後排,保證相對位置不變。以為是代碼:#include"test_char_exchange.h"#include<stdlib.h>#include<stdio.h>int isup(char c){return c>='A'&&c<='Z'?1:0;}void swap(char *c1,char *c2){int t=*c1;*c1=*c2;*c2=t;}int
Time of Update: 2018-12-05
之前發過一篇部落格,寫的是關於一條語句輸出迴文值,在發那篇部落格的時候並沒有看懂那條語句的執行過程,現在補充道這裡。原來那篇部落格的地址是:http://blog.csdn.net/jianzhibeihang/archive/2009/12/06/4952037.aspx 今天特定在c版發了貼問了下,發現了很多好的回帖。版裡的大牛還是很多啊! 原帖地址為:http://topic.csdn.net/u/20091209/10/d7cc1cc3-3eff-43d2-8096-c66a7899