摘要: 题目:类CMyString的声明如下:class CMyString{public: CMyString(char* pData = NULL); CMyString(const CMyString& str); ~CMyString(void); CMyString&operator= (const CMyString& str);private: char* m_pData;}; 请实现其赋值运算符的重载函数,要求异常安全,即当对一个对象进行赋值时发生异常,对象的状态不能改变。要求异常安全,应该禁止使用new和delete操作View C... 阅读全文
posted @ 2012-05-10 23:45 徐露 阅读(226) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 int Strlen(const char *str) 5 { 6 if (str==NULL) 7 { 8 return 0; 9 }10 if (*str != '\0')11 {12 return 1+Strlen(++str);13 }14 else 15 return 0;16 }17 18 int Strlen1(const char* str)19 {... 阅读全文
posted @ 2012-05-10 23:15 徐露 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 要求不能使用乘除法、for、while、if、else、switch、case 等关键字以及条件判断语句View Code 1 #include <iostream> 2 using namespace std; 3 4 /*第一种方案*/ 5 int sum1(int n) 6 { 7 int temp=0; 8 n && (temp=sum1(n-1)); 9 return temp+n;10 }11 /* 第二种方案 */12 class A13 {14 public:15 A()16 {17 N++;18 s... 阅读全文
posted @ 2012-05-10 19:14 徐露 阅读(148) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #define MAXLEN 10 4 #define K 3 5 6 7 void HeapAdjust(int array[], int i, int len) 8 { 9 int temp=array[i];10 int j;11 for (j=2*i; j<len; j*=2)12 {13 if (j<len && array[j] < array[j+1])14 {15 ... 阅读全文
posted @ 2012-05-10 18:25 徐露 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 算法设计:1、当访问到某一节点时,把该结点的值添加到当前和变量,且把该结点压vector中。2、若结点为叶子结点,且当前和变量等于期望的和,则打印vector中的结点值,即为所需的路径。3、若结点不是叶子结点,继续访问它的左孩子结点,访问它的右孩子结点。4、删除该结点。包括从当前和变量中减去结点值,从vector中弹出结点值。#include <iostream>#include <vector>#include <stdlib.h>using namespace std;typedef struct node{ int data; struct node* 阅读全文
posted @ 2012-05-10 16:15 徐露 阅读(480) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int maxSum(int* a, int n) { int sum=0; int b=0; for(int i=0; i<n; i++) { if(b<0) b=a[i]; else b+=a[i]; if(sum<b) sum=b; } return sum; } int maxSu... 阅读全文
posted @ 2012-05-10 15:07 徐露 阅读(198) 评论(0) 推荐(0) 编辑