- 博客(8)
- 资源 (2)
- 收藏
- 关注
转载 More effective c++ 11(禁止异常(exceptions)流出destructors之外)
#include using namespace std; double fun(double x, double y) //定义函数 { if(y==0) { throw y; //除数为0,抛出异常 } return x/y; //否则返回两个数的商 } class B { public: ~B() { int a = fun(4,0); //因为除数
2014-07-28 17:28:52 461
转载 转:C++的异常处理
一、什么是异常处理 一句话:异常处理就是处理程序中的错误。 二、为什么需要异常处理,以及异常处理的基本思想 C++之父Bjarne Stroustrup在《The C++ Programming Language》中讲到:一个库的作者可以检测出发生了运行时错误,但一般不知道怎样去处理它们(因为和用户具体的应用有关);另一方面,库的用户知道怎样处理这些错误,但却
2014-07-28 16:37:10 196
原创 shared_ptr
template class SmartPointer { public: SmartPointer(T * ptr) { ref = ptr; ref_count = (unsigned*)malloc(sizeof(unsigned)); *ref_count = 1; } SmartP
2014-07-09 23:52:19 215
转载 auto_ptr的源码
namespace std { template class auto_ptr { private: T* ap; public: // constructor & destructor ----------------------------------- (1) explicit auto_ptr (T* ptr = 0) throw() : a
2014-07-09 23:35:47 312
原创 QuickSort
void qsort(int s[], int l, int r) { int i, j, x; if (l { i = l; j = r; x = s[i]; while (i { while(i x) j--; /* 从右向左找第一个小于x的
2014-07-09 20:23:24 220
原创 分治算法之汉诺塔
#include using namespace std; void hanoi(int n,char one,char two,char three); int main() { int m; cout<<"输入盘子数:"; cin>>m; hanoi(m,'A','B','C'); } void move(char x,c
2014-07-07 23:06:20 326
原创 pop push min O(1)
#include #include using namespace std; #include #define STACK_LEN 7 typedef struct { int data; int min; }stackitem; typedef struct { stackitem data[STACK_LEN]; int top; }stac
2014-07-06 19:53:14 305
转载 Write a C program to print all permutations of a given string
A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permu
2014-07-04 00:29:39 480
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人