- 博客(180)
- 资源 (11)
- 收藏
- 关注
原创 谜题1.6 操作符的优先级和求值顺序
#include #include #define PRINT3(x, y, z) \printf(#x " = %d\t" #y " = %d\t" #z " = %d\n",x, y, z)int main(void){ int x, y, z; x = y = z = 1; ++x || ++y && ++z;PRINT3(x, y, z);
2011-11-30 23:04:02 632
原创 谜题1.5 关系操作符和条件操作符
#include #include #define PRINT(int) printf(#int" = %d\n",int)int main(void){ int x = 1, y = 1, z = 1; x += y += z; PRINT(x < y ? y : x); PRINT(x < y ? x++ : y++); PRI
2011-11-30 22:56:44 537
原创 谜题1.4 二进制位操作符
#include #include #define PRINT(int) printf(#int" = %d\n",int)int main(void){ int x, y, z; x = 03; y = 02; z = 01; PRINT(x | y & z); PRINT(x | y & ~z); PRINT(x ^ y & ~
2011-11-30 22:51:50 634
原创 谜题1.3 逻辑操作符和增量操作符
#include #include #define PRINT(int) printf("%d\n",int)int main(void){ int x, y, z; x = 2; y = 1; z = 0; x = x && y || z;PRINT(x); PRINT( x || !y && z); x = y = 1;
2011-11-30 22:46:41 655
原创 谜题1.2 赋值操作符
#include #define PRINTX printf("%d\n",x)int main(void){ int x = 2, y, z; x *= 3 + 2; PRINTX; x *= y = z = 4; PRINTX; x = y == z; PRINTX; x == (y = z);
2011-11-30 21:45:04 687
原创 谜题1.1 基本算术操作符
#include int main(void){ int x; x = -3 + 4 * 5 - 6; printf("%d\n",x); x = 3 + 4 % 5 - 6; printf("%d\n",x); x = -3 * 4 % -6 / 5; printf("%d\n",x); x = (7 + 6
2011-11-30 21:37:01 589
原创 这些你见过吧?
typedef T value_type;typedef T* pointer;typedef T* const const_pointer;typedef T& reference;typedef T& const const_reference;typedef size_t size_type;typedef ptrdiff_t difference_type;
2011-11-30 08:23:44 207
原创 深拷贝
什么时候调用拷贝构造函数1--->当一个对象以值传递的方式传入函数2--->当一个对象以值传递的方式返回函数3--->当用一个对象初始化另一个对象时拷贝构造函数分为浅拷贝和深拷贝当类拥有堆内存资源时,必须用深拷贝#include #include using namespace std;class DeepCopy{ public: De
2011-11-29 23:23:46 330
原创 二维数组与指针数组
//二维数组char wName[8][13] 1 2 3 4 5 6 7 8 9 10 11 12 13wName+0:------>s u n d a y \0 \0 \0 \0 \0 \0 \0wName+1:------>m o n d a y \0 \0 \0 \0 \0 \0 \0
2011-11-29 23:04:33 227
原创 指针数组与数组指针
/* 指针数组(int *p[2]):列不确定 数组指针(int (*p)[2]):行不确定*/#include using namespace std;int main(void){ //指针数组 int *p[2]; int a[4] = {11, 22, 33, 44}; int b[6] = {14, 25,
2011-11-29 22:47:54 313
原创 尽量将const写在类型后面
typedef string *pstring; const pstring cstr; 请问cstr变量是什么类型? const string * cstr 很多人以为是上面这个吧! 非也,它是下面这个 string * const cstr 所以,如果你将
2011-11-29 21:02:06 539 1
原创 用类似迭代器的方式输出数组
#include using namespace std;int main(void){ const size_t arr_sz = 5; int int_arr[arr_sz] = {0, 1, 2, 3, 4}; for (int *pbegin = int_arr, *pend = int_arr + arr_sz; pbegin != pend;
2011-11-29 20:35:27 292
原创 哥们,你见过这样的下标运算么?
#include using namespace std;int main(void){ int ia[] = {0, 2, 4, 6, 8}; int *p = &ia[2]; cout << *p << endl; int j = p[1]; cout << j << endl; int k = p[-2]; c
2011-11-29 20:31:27 201
原创 ptrdiff_t
#define __PTRDIFF_TYPE__ long inttypedef __PTRDIFF_TYPE__ ptrdiff_t;
2011-11-29 20:26:58 642
原创 指针与数组
#include using namespace std;int main(){ char ch[] = "hello world"; char *pch = "hello world"; cout << ch << endl; cout << pch << endl; return 0;}hello worldhell
2011-11-29 20:21:38 182
原创 strlen与sizeof
#include #include using namespace std;int main(void){ const char cArray[20] = "Daniel"; cout << strlen(cArray) << endl; cout << sizeof(cArray) << endl; return 0;}
2011-11-29 20:08:33 174
原创 数组的初始化
#include using namespace std;int array1[10];void output(){ int array2[10]; for (int i = 0; i < 5; ++i) { cout << i << "\t" << array2[i] << endl; }}void output1
2011-11-29 20:01:08 266
原创 等值首尾和
/* 功能:计算一个算组,它的前置和和后置和有多少个相等 例子:x[] = {3, 6, 2, 1, 4, 5, 2}; 前置和:3 9 11 12 16 21 23 后置和:2 7 11 12 14 20 23 作者:朱鑫 日期:2011/11/29*/#include using namespace
2011-11-29 17:21:48 588
原创 两数组最短距离
/* 功能:计算两个数组的最短距离 例子:x[] = {1, 3, 5, 7, 9}; y[] = {2, 6, 8}; min = 1; 作者:朱鑫*/#include #include using namespace std;int min_distance(int *, int *, int, in
2011-11-29 17:00:02 456
原创 双向链表
//Node.htemplate class Node{ public: T data; Node *lNode; Node *rNode; Node() { ; } Node(const T &x) { data = x; } ~Node(
2011-11-29 11:41:33 182
原创 循环链表
//Node.htemplate class Node{ public: Node() { ; } Node(const T &x) { data = x; } ~Node() { ; } T data; Node
2011-11-29 10:28:44 204
原创 单链表逆置(C++)
//结点类 template class Node{ public: Node() { ; } Node(const T &x) { data = x; } ~Node() { ; } T data; Node *
2011-11-28 21:13:43 360
原创 链表模板类
/* LinearList.h是基类 Node.h是结点类 SingleList.h是链表类 SingleList.cpp是SingleList.h的具体实现 main.cpp是测试*///LinearList.husing namespace std;template class LinearList{ public: Linear
2011-11-28 19:51:25 419
原创 等值数目
#include using namespace std;template int coincidenceCount(T*, T*, int, int);int main(void){ int m, n; int *piArray1; int *piArray2; while (cin >> m >> n) {
2011-11-28 11:49:53 274
原创 支配值数目
/* 已知f[]与g[]两个整数数组,元素都已经从小到大排列,试编写程序算出f[] 中每一个元素比g[]中元素大的个数的总数。换句话说,f[0]比g[]中多少个 元素大、f[1]比g[]中多少个元素大等,这些值的总和就是所要求的答案。*/#include using namespace std;template int dominantCount(
2011-11-28 11:34:59 267
原创 看一个例子,指针与数组的区别
#include using namespace std;int main(void){ char array[] = "Hello World"; const char *p = "Hello World"; cout << sizeof(array) / sizeof(*array) << endl; cout << sizeof(p) /
2011-11-28 11:11:35 273
原创 Stack模板
//Stack.htemplate class Stack{ public: Stack() { ; } virtual void Push(const T &x) = 0; virtual void Pop() = 0; virtual T Top() const = 0; virtua
2011-11-26 22:43:48 579 1
转载 C++内存分配
在C++中,内存分成5个区,他们分别是堆、栈、自由存储区、全局/静态存储区和常量存储区。 栈,就是那些由编译器在需要的时候分配,在不需要的时候自动清除的变量的存储区。里面的变量通常是局部变量、函数参数等。在一个进程中,位于用户虚拟地址空间顶部的是用户栈,编译器用它来实现函数的调用。和堆一样,用户栈在程序执行期间可以动态地扩展和收缩。 堆,就是那些由 new 分配的内存块,他们的释放
2011-11-26 21:58:30 462
原创 快速排序
#include using namespace std;const int MAXSIZE = 100;void quick_sort(int [], int, int);int main(void){ int n; int array[MAXSIZE]; while (cin >> n) { for (int i =
2011-11-26 19:24:40 256
原创 选择排序
#include const int MAXSIZE = 100;using namespace std;void select_sort(int [], int);int main(void){ int n; int array[MAXSIZE]; while (cin >> n) { for (int i = 0;
2011-11-26 18:59:54 262
原创 插入排序
/* 功能:插入排序 例如: 5 3 8 2 9 第一次 :5 5 8 2 9 3 5 8 2 9 第二次 :3 5 8 2 9 第三次 :3 5 8 8 9 3 5 5 8 9
2011-11-26 01:47:56 312
原创 华美海润的笔试题(C语言)
/* 求最大公约数*/#include using namespace std;int function(int a, int b){ while (b) { if (a > b) { a -= b; } else {
2011-11-25 12:30:29 2873
原创 华美海润的笔试题(数据库)
/* 建立数据库test1 建立数据表Teacher,Student,Grade 插入各表的数据*/create database test1;create table Teacher( TeacherId varchar(10) primary key, Name varchar(20), Email varchar(20),)insert int
2011-11-25 12:07:57 4460
原创 最小拉丁矩阵
#includeusing namespace std;int main(void){ int n; int temp; while (cin >> n) { for (int i = 1; i <= n; ++i) { temp = i; while (te
2011-11-22 23:29:20 436
原创 约瑟夫问题
#include #include #include using namespace std;char *chArray;void Joseph(int n, int m);int main(void){ int n, m; while (cin >> n >> m) { chArray = (char*)malloc((
2011-11-22 22:53:32 474 1
原创 大端模式和小端模式
#include using namespace std;int main(void){ cout << sizeof(char) << endl; cout << sizeof(short) << endl; cout << sizeof(int) << endl; cout << sizeof(long) << endl; cout
2011-11-22 22:01:16 226
原创 求每隔1000素数的个数
#include const int MAX = 1000000;using namespace std;bool isPrime(int n);int count(int n);int main(void){ for(int i = 0; i < MAX; i += 1000) { cout << count(i) <<endl;
2011-11-22 21:59:01 309
原创 指针常量与常量指针
在说道“指针常数”时,我们的意思是一个被声明为“char *const chrPtr”形式的指针,你不能把它修改为指向内存中另外一处的地址,但可以用它来改变它所指向的地址处的数据内容。这与更为常见的“常数指针”是有区别的。在说道“常数指针”时,我们的意思是一个被声明为“const char *chrPtr”形式的指针,你可以把它修改为指向内存中另外一处的地址,但不能用它来修改它所指向的地址
2011-11-22 19:40:42 284
原创 凯撒密码
文件结构如上图/* 作者:朱鑫 语言: C++ 说明:从in.txt读取明文或者密文,经过加密或者解密后输出到 out.txt中,如果out.txt与test.txt一样则加密或者解密 成功,否则,不成功。 日期:2011/11/21 邮箱:zhuxin@nwsuaf.edu.cn*/#inc
2011-11-22 19:01:05 717
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人