2013年7月24日

摘要: -----Test.h文件-----------------------------------------#ifndef TEST_H#define TEST_H#includeusing namespace std;templateclass CMyStack{private: struct Item { public: T data; Item *next; Item():next(NULL){} }; Item *m_data; Item *m_min; CMyStack(const CMyStack&); CMyStack& operator=(const CMySt 阅读全文
posted @ 2013-07-24 15:03 dyc0113 阅读(500) 评论(0) 推荐(0) 编辑

2013年7月23日

摘要: enum{Valid,Invalid};int g_valid;double Power(double base,int exponent){ g_valid=Invalid; if(abs(base)=0) sign=1; else { sign=-1; n=-n; } while(n>0) { if(n%2==0) { b=b*b; n=n>>1; } else { ret=ret*b; n=n-1; } } g_valid=Valid; if(sign>0) { return ret; } else { return 1/ret; }} 阅读全文
posted @ 2013-07-23 17:11 dyc0113 阅读(200) 评论(0) 推荐(0) 编辑
摘要: bool g_Increase=false;char *Increase(char *s){ g_Increase=false; if(s==NULL) return NULL; int len=strlen(s); if(len==1) return s; int i=len-2; while(i>=0&&s[i]>=s[i+1]) i--; if(ikey;j++); if(j==len) { swap(s[i],s[j-1]); j=len-1; } else { j-=1; swap(s[i],s[j]); } i++; while(i<j) { sw 阅读全文
posted @ 2013-07-23 17:09 dyc0113 阅读(347) 评论(0) 推荐(0) 编辑
摘要: int min(int arr[],int n){ int i=0,j=n-1; if(arr[i]x) i=m+1; else if(arr[m]arr[i]?arr[i]:x;} 阅读全文
posted @ 2013-07-23 11:23 dyc0113 阅读(121) 评论(0) 推荐(0) 编辑

2013年7月22日

摘要: #include#include#include#include#include#include#include"Test.h"using namespace std;struct Node{ int data; Node *left; Node *right;};int pre[]={1,2,4,7,3,5,6,8};int mid[]={4,7,2,1,5,3,8,6};Node *f(int pre[],int a,int b,int mid[],int m,int n){ if(b-a+1!=n-m+1) throw std::exception(... 阅读全文
posted @ 2013-07-22 22:49 dyc0113 阅读(226) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#include#include#include"Test.h"void replace(char *s) // 先计算空格总数,然后从后面开始替换,可以计算出空格后面字符的偏移量{ assert(s!=NULL); int len =strlen(s); int i,j; int x; for(i=0,x=0;i=0;i--) { if(s[i]==' ') { spaceCount++; int shift=(x-sp... 阅读全文
posted @ 2013-07-22 17:02 dyc0113 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目: 在一个二维数组中,每一行都按照从左到右的递增顺序,每一列都按照从上到下的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。1 2 8 92 4 9 124 7 10 136 8 11 15#include#include#include#include#include#include#include"Test.h"bool findMatrix(int **p,int m,int n,int x){ assert(p!=NULL); while(m>=1&&n>=1) { if(p[0][n-1]> 阅读全文
posted @ 2013-07-22 16:49 dyc0113 阅读(142) 评论(0) 推荐(0) 编辑
摘要: class Singleton // 这是两种方式{private: static Singleton single; Singleton(){} Singleton &operator=(Singleton & s)// 屏蔽拷贝构造函数和赋值操作符 { } Singleton(const Singleton &s){}public: int m_value; static Singleton * getInstance() { return &single; }};Singleton Singleton::... 阅读全文
posted @ 2013-07-22 15:54 dyc0113 阅读(115) 评论(0) 推荐(0) 编辑

2013年7月20日

摘要: 只能指针实现了指针指向对象的共享。同时避免了悬垂指针等问题。通过对运算符的重载它可以像普通指针一样的操作。只要有一个智能指针指向这个对象,那么这个对象就不会被释放掉。#include#include#include#include#includeusing namespace std;// 引用计数实现智能指针templateclass U_Ptr{ size_t use; T *ip; U_Ptr(T *p):ip(p),use(1){} template friend class HasPtr; ~U_Ptr(){delete ip;}};templat... 阅读全文
posted @ 2013-07-20 13:47 dyc0113 阅读(146) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#includeusing namespace std;struct Exmpl{ Exmpl() { std::cout<<"Exmpl()"<<endl; } Exmpl(const Exmpl &) { cout<<"Exmpl( const Exmpl&)"<<endl; } Exmpl& operator=(const Exmpl &rhe) { cout<<"operator=( 阅读全文
posted @ 2013-07-20 11:37 dyc0113 阅读(183) 评论(0) 推荐(0) 编辑

导航