资源简介
DT数据结构代码 DTlib.

代码片段和文件信息
#include
#include
#include “DTString.h“
#include “Exception.h“
using namespace std;
namespace DTlib
{
int* String::make_pmt(const char* p)
{
int len = strlen(p);
int* ret = static_cast(malloc(sizeof(int) * len));
if( ret != NULL )
{
int ll = 0;
ret[0] = 0;
for(int i = 1; i < len; i++)
{
while( (ll>0) && (p[ll] != p[i]) )
{
ll = ret[ll - 1];
}
if( p[ll] == p[i] )
{
ll++;
}
ret[i] = ll;
}
}
return ret;
}
int String::kmp(const char* s const char* p)
{
int ret = -1;
int s1 = strlen(s);
int p1 = strlen(p);
int* pmt = make_pmt(p);
if((pmt != NULL) && (0 < p1) && (p1 <= s1))
{
for(int i=0 j=0; i {
while((j > 0) && (s[i] != p[j]))
{
j = pmt[j-1];
}
if(s[i] == p[j])
{
j++;
}
if(j == p1)
{
ret = i + 1 - p1;
break;
}
}
}
free(pmt);
return ret;
}
void String::init(const char* s)
{
m_str = strdup(s);//m_str指向堆空间拷贝字符串
if( m_str )
{
m_length = strlen(m_str);
}
else
{
THROW_EXCEPTION(NoEnoughMemoryException “No memory to create String object...“);
}
}
String::String()
{
init(““);
}
String::String(char c)
{
char s[] = {c ‘\0‘};
init(s);
}
String::String(const char* s)
{
init(s ? s : ““);
}
String::String(const String& s)
{
init(s.m_str);
}
int String::length() const
{
return m_length;
}
const char* String::str() const
{
return m_str;
}
bool String::equal(const char* l const char* r int len) const
{
bool ret = true;
for(int i = 0; i < len && ret; i++)
{
ret = ret && (l[i] == r[i]);
}
return ret;
}
bool String::startWith(const char* s) const
{
bool ret = (s != NULL);
if( ret )
{
int len = strlen(s);
ret = (len < m_length) && equal(m_str s len);
}
return ret;
}
bool String::startWith(const String& s) const
{
return startWith(s.m_str);
}
bool String::endOf(const char* s) const
{
bool ret = (s != NULL);
if( ret )
{
int len = strlen(s);
char* str = m_str + (m_length - len);
ret = (len < m_length) && equal(str s len);
}
return ret;
}
bool String::endOf(const String& s) const
{
return endOf(s.m_str);
}
String& String::insert(int i const char* s)
{
if((0 <= i) && (i <= m_length))
{
if((s != NULL) && (s[0] != ‘\0‘))
{
int len = strlen(s);
char* str = reinterpret_cast(malloc(m_length + len +1));
if(str != NULL)
{
strncpy(str m_str i);
strncpy(str + i s len);
strncpy(str + i
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1495 2019-08-04 19:12 DTlib\Array.h
文件 14846 2019-08-05 10:08 DTlib\BTree.h
文件 540 2019-08-05 07:14 DTlib\BTreeNode.h
文件 3244 2019-08-03 19:27 DTlib\CircleList.h
文件 64368 2019-08-05 22:26 DTlib\DTlib
文件 752 2019-08-05 13:46 DTlib\DTlib.pro
文件 23742 2019-12-26 08:59 DTlib\DTlib.pro.user
文件 18452 2019-08-05 22:59 DTlib\DTlib.pro.user.2.5pre1
文件 8835 2019-08-04 05:15 DTlib\DTString.cpp
文件 2318 2019-08-04 05:07 DTlib\DTString.h
文件 4838 2019-08-03 21:30 DTlib\DualCircleList.h
文件 5507 2019-08-03 20:48 DTlib\Dualli
文件 2199 2019-07-29 22:12 DTlib\DynamicArray.h
文件 1976 2019-07-29 19:52 DTlib\DynamicList.h
文件 2869 2019-08-03 15:37 DTlib\Exception.cpp
文件 4604 2019-12-25 17:16 DTlib\Exception.h
文件 4604 2019-12-26 09:19 DTlib\Exception.h.autosave
文件 14114 2019-08-05 22:24 DTlib\Graph.h
文件 7845 2019-08-05 02:57 DTlib\GTree.h
文件 578 2019-08-05 03:01 DTlib\GTreeNode.h
文件 4962 2019-08-03 20:48 DTlib\li
文件 1610 2019-08-03 23:56 DTlib\li
文件 897 2019-08-03 22:44 DTlib\li
文件 23350 2018-12-03 00:10 DTlib\LinuxList.h
文件 877 2019-08-03 11:24 DTlib\List.h
文件 7525 2019-08-05 17:15 DTlib\ListGraph.h
文件 543 2019-12-25 17:27 DTlib\main.cpp
文件 7038 2019-08-05 13:54 DTlib\Makefile
文件 6327 2019-08-05 17:15 DTlib\MatrixGraph.h
文件 567 2019-08-03 22:08 DTlib\ob
............此处省略19个文件信息
- 上一篇:未来教育全套考试免激活.txt
- 下一篇:QT项目code.rar
相关资源
- bp神经网络源代码,可直接运行
- 随机森林R语言代码
- 计算机图形学 边填充算法实现代码
- 直流无刷电机方波驱动 stm32 例程代码
- 仿知乎界面小程序源代码
- 贪吃蛇源代码.fla
- 周立功开发板ProASIC3实验-syn_FIFO代码
- IMX385驱动代码.zip
- dotnet 写字板 实验 源代码 不好请要不
- 数据结构年终考题范围和答案 耿国华
- 图像二维小波变换的实现源代码
- 八三编码器设计 VHDL代码 简单,包附
- linux应用层的华容道游戏源代码
- 交通咨询模拟系统完整代码
- http请求状态代码
- 数值分析所有实验代码
- 数据结构 朱战力 习题解答 数据结构
- 网上拍卖系统完整源代码
- 音乐代码转换软件 单片机编程时用
- CSMA/CD等动画演示加源代码
- silicon lab公司的收音IC SI47XX全套开发工
- 用51单片机实现G代码翻译
- 合同管理系统的源代码(附数据库)
- 数据结构课程设计 6 1 彩票系统
- 用VC 编写的仿QQ聊天室程序源代码
- 教学计划编制系统
- web班级网站设计代码
- 38k单片机红外发送代码、keil
- STM32F103 串口程序(完整版)
- 网络唤醒代码
评论
共有 条评论