用两个栈模拟队列的思想就是“倒水思想”,这里我们用自定义类型模拟出线性表,再用线性表做容器实现栈的数据结构,最后用栈来实现队列,代码如下:#include<iostream>
#include<string>
#include<cassert>
struct__TrueType//类型萃取
{
boolGet()
{
re..
分类:
其他好文 时间:
2016-04-09 01:49:02
阅读次数:
219
双向链表结构图:节点结构:代码实现:/*DList.h*/
#pragmaonce
#include<iostream>
#include<cassert>
usingnamespacestd;
typedefintDataType;
structNode
{
Node(constDataType&x)
:_data(x)
,_next(NULL)
,_prev(NULL)
{}
DataType_data; //数..
分类:
编程语言 时间:
2016-03-26 20:34:12
阅读次数:
354
要注意使用断言判断传入的字符串非空。 1 #include <cassert> 2 3 //字符串复制 4 char* StrCpy(char *dest, const char *src) 5 { 6 assert(dest != nullptr && src != nullptr); 7 cha
分类:
编程语言 时间:
2016-03-11 22:03:04
阅读次数:
155
#define_CRT_SECURE_NO_WARNINGS1
#include<iostream>
#include<cassert>
usingnamespacestd;
//string编写
/*版本1以前的版本*/
/***************
classString
{
public:
//错误String(char*str=NULL)
String(char*str="")
:_str(newchar[strlen(str)+1])
{
}
Str..
分类:
编程语言 时间:
2016-03-10 01:53:23
阅读次数:
276
写时拷贝(COW)的实现:#include<iostream>
#include<cassert>
usingnamespacestd;
classString
{
public:
String(char*str="")
:_str(newchar[strlen(str)+sizeof(int)+1])
{
*(int*)_str=1;
_str+=4;
strcpy(_str,str);
}
String(constString&am..
分类:
其他好文 时间:
2016-03-09 19:09:10
阅读次数:
151
★C++实现双向链表的基础操作(类的实现)#include<iostream>
#include<cassert>
usingnamespacestd;
typedefintDataType;
classdouble_link_list
{//定义双向链表类,包括了双向的前驱和后继指针,以及对象的初始化
public:
friendclassListNode;
double_link_li..
分类:
编程语言 时间:
2016-03-05 22:09:55
阅读次数:
218
找到通路1111111111000111111111011111111100011111110101111111010111111101011111110101111111010111111101111111#include<iostream>
#include<cassert>
#include<stack>
usingnamespacestd;
structpos
{
introw;
intcol;
};
stack<pos>paths;
voidC..
分类:
其他好文 时间:
2016-03-01 19:17:11
阅读次数:
167
文件名: (assert.h) 这是一个C语言的诊断库,assert.h文件中定义了一个可作为标准调试工具的宏函数: assert ;下面介绍这个宏函数:assert函数原型:void assert (int expression);函数描述: 如果这个宏函数形式的参数(expression...
分类:
其他好文 时间:
2015-12-20 23:55:49
阅读次数:
196
断言是很早之前就有的东西了,只需要引入cassert头文件即可使用。往往assert被用于检查不可能发生的行为,来确保开发者在调试阶段尽早发现“不可能”事件真的发生了,如果真的发生了,那么就表示代码的逻辑存在问题。最好的一点就是,断言只在Debug中生效,因此对于Release版本是没有效率上的.....
分类:
编程语言 时间:
2015-09-11 10:28:51
阅读次数:
155
assertassert是一个预处理宏,由预处理器管理而非编译器管理,所以使用时都不用命名空间声明,如果你写成std::assert反而是错的。使用assert需要包含cassert或assert.h,用法如下:assert(expr)
assert主要用途是:用于调试,检测一些不应该出现的情况。如果expr为假(即为0),assert输出信息并终止程序的运行,如果expr为真,则什么也做。asse...
分类:
其他好文 时间:
2015-07-27 00:20:44
阅读次数:
122