
C++
YellowTre
程序猿
展开
-
国际象棋中用8个皇后摆在不同的格而且互相不牵制有多少种不同的摆法
#include "iostream"//#include <vector>using namespace std;int count = 0;bool IsDuiJiao(int a[],int data,int cur){ for (int i=0; i<cur; i++) { if (abs(cur-i) == abs(data - a[i]))原创 2016-07-01 18:46:18 · 2454 阅读 · 0 评论 -
顺时针打印矩阵
#include<iostream>#include <iomanip>using namespace std;#define nr 10 //定义矩阵的行和列#define nl 7void main(){ int a1[nr][nl]; int num = 0; for (int i=0;i<nr;i++) { for (int j=0原创 2016-06-29 14:46:48 · 578 阅读 · 0 评论 -
合并两个排序的链表
#include<iostream>using namespace std;struct MyNode{ int data; MyNode *next;};struct MyList{ MyNode *head;};void CreatMyList(MyList *ml,int n){ if (NULL == ml ) { retu原创 2016-06-28 22:07:23 · 267 阅读 · 0 评论 -
public,private,protected
#include<iostream>using namespace std;//////////////////////////////////////////////////////////////////////////class A //父类{private: int privatedateA;protected: int protecteddateA;public:转载 2016-05-30 16:06:33 · 284 阅读 · 0 评论 -
反转链表
#includeiostream>using namespace std;struct MyNode{ int data; MyNode *next;};struct MyList{ MyNode *head;};void CreatMyList(MyList *ml,int n){ if (NULL == ml || n1) {原创 2016-06-28 10:36:43 · 225 阅读 · 0 评论 -
vs调试
VS调试时按Alt+8打开汇编窗口 Alt+7打开堆栈窗口 Alt+6打开内存窗口 Alt+5打开寄存器窗口看每句C对应的汇编、堆栈、内存和寄存器变化原创 2016-05-26 15:24:30 · 308 阅读 · 0 评论 -
vector的reserve和resize
vector 的reserve增加了vector的capacity,但是它的size没有改变!而resize改变了vector的capacity同时也增加了它的size!原因如下: reserve是容器预留空间,但在空间内不真正创建元素对象,所以在没有添加新的对象之前,不能引用容器内的元素。加入新的元素时,要调用push_back()/insert()函数。转载 2016-05-26 11:18:58 · 270 阅读 · 0 评论 -
C指针强制类型转换
int main(void){unsigned int a = 0xFFFFFFF7;unsigned char i = (unsigned char)a;char* b = (char*)&a;printf("%08x, %x", i, *b);return 0;}结果 000000F7 FFFFFFF7解析:int 4字节,他在内存中是反着存转载 2016-05-18 20:16:50 · 484 阅读 · 0 评论 -
全排列abc: a,b,c,ab,ac,bc,abc
#include "iostream"#include <vector>using namespace std;void zuhe(char *src,int len, int cur, vector<char> &sc){ if (len==sc.size()) { vector<char>::const_iterator vci = sc.begin();原创 2016-07-01 11:38:12 · 1770 阅读 · 0 评论 -
字符串的排列
#include "iostream"using namespace std;void permu(char * pStr, char * pBegin){ if (*pBegin == '\0') { printf("%s\n",pStr); } else { for (char *pCh = pBegin; *pCh !转载 2016-07-01 11:46:56 · 262 阅读 · 0 评论 -
指针传递,引用传递
#include "iostream"#include <vector>using namespace std;void swp(int*a, int*b){ int *temp; temp = a; a = b; b = temp;}void swp2(int *a, int *b){ int temp; temp = *a; *原创 2016-07-01 11:56:26 · 316 阅读 · 0 评论 -
打印全排列数字
#include "iostream"using namespace std;bool HasIn(int a[],int data,int cur){ for (int i=0; i<cur; i++) { if (data == a[i]) { return true; } } retur原创 2016-07-01 11:43:57 · 839 阅读 · 0 评论