一、字符串 1、字符串的旋转:前m个字符移动到尾部 蛮力移位:将所有字符前移,将第一个字符放到尾部,调用m次此方法 三步反转:前m-1个反转,n-m个反转,整体反转;反转采用双指针,一个加一个减,通过中间字符交换 2、字符串的包含:判断短字符串的字符都在长字符串中 蛮力轮训:两个循环,ij对应字符不
原创
2022-05-27 17:46:24
77阅读
3.1. 字符串移位包含问题方法1:分别对字符串进行循环移1位,2位,3位…,来判断给定的字符串是否是其中一个字串.复杂度是O(n^3)方法2:这也是一种利用空间换时间的方法.代码如下, 为了简便实现,采用了C库中的字符串操作函数:#if 0/* * 3.1 */bool isRotate(char...
转载
2023-05-31 16:57:56
46阅读
代码清单3-14
// 层次遍历二叉树
// @param
// root,二叉树的根节点
// depth,树的深度
void PrintNodeByLevel(Node* root, int depth)
{
for(int level = 0; level < depth; level++)
{
PrintNodeAtLevel(root, le...
原创
2022-03-04 10:46:18
64阅读
代码清单3-4
while(true)
{
// n为电话号码的长度
for(i = 0; i < n; i++)
printf("%c", c[number[i]][answer[i]]);
printf("\n");
int k = n - 1;
while(k >= 0)
{
i...
原创
2022-03-04 10:54:59
34阅读
代码清单3-3
for(answer[0] = 0; answer[0] < total[number[0]]; answer[0]++)
for(answer[1] = 0; answer[1] < total[number[1]]; answer[1]++)
原创
2022-03-04 11:05:35
20阅读
代码清单3-7void DeleteRandomNode(node* pCurrent){ Assert(pCurrent != NULL); node* pNext = pCurrent -> next; if(pNext != NULL) { pCurrent -> next = pNext -> next; ...
原创
2021-08-18 02:23:55
68阅读
代码清单3-9class stack{public: stack() { stackTop = -1; maxStackItemIndex = -1; } void Push(Type x) { stackTop++; if(stackTop >= MAX...
原创
2021-08-18 02:23:56
51阅读
代码清单3-5void RecursiveSearch(int* number, int* answer, int index, int n){ if(index == n) { for(int i = 0; i < m; i++) printf("%c", c[number[i]][answer[i]]); ...
原创
2021-08-18 02:23:57
49阅读
代码清单3-6Int CalculateStringDistance(string strA, int pABegin, int pAEnd, string strB, int pBBegin, int pBEnd) { if(pABegin > pAEnd) { if(pBBegin > pBEnd) r...
原创
2021-08-18 02:23:59
65阅读
代码清单3-4while(true){ // n为电话号码的长度 for(i = 0; i < n; i++) printf("%c", c[number[i]][answer[i]]); printf("\n"); int k = n - 1; while(k >= 0) { i...
原创
2021-08-18 02:25:59
66阅读
代码清单3-15
// 层次遍历二叉树
// root,二叉树的根节点
void PrintNodeByLevel(Node* root)
{
for(int level=0; ; level++)
{
if(!PrintNodeAtLevel(root, level))
break;
cout <&...
原创
2022-03-04 10:45:52
17阅读
代码清单3-13
// 输出以root为根节点中的第level层中的所有节点(从左到右), 成功返回1,
// 失败则返回0
// @param
// root 为二叉树的根节点
// level为层次数,其中根节点为第0层
int PrintNodeAtLevel(Node* root, int level)
{
if(!root || level < 0)
...
原创
2022-03-04 10:46:12
25阅读
代码清单3-12
// ReBuild.cpp : 根据前序及中序结果,重建树的根节点
//
// 定义树的长度。为了后序调用实现的简单,我们直接用宏定义了树节点的总数
#define TREELEN 6
// 树节点
struct NODE
{
原创
2022-03-04 10:47:20
16阅读
代码清单3-2
char c[10][10] =
{
"", //0
"", //1
"ABC", //2
"DEF", //3
"GHI", //4
"JKL", //5
"MNO", //6
原创
2022-03-04 10:56:48
15阅读
代码清单3-16
// 按层次遍历二叉树
// @param
// root,二叉树的根节点
void PrintNodeByLevel(Node* root)
{
原创
2022-03-04 11:07:37
26阅读
代码清单3-14// 层次遍历二叉树// @param// root,二叉树的根节点// depth,树的深度void PrintNodeByLevel(Node* root, int depth){ for(int level = 0; level < depth; level++) { PrintNodeAtLevel(root, le...
原创
2021-08-18 02:23:41
56阅读
代码清单3-11// 数据结构定义struct NODE{ NODE* pLeft; // 左子树 NODE* pRight; // 右子树 int nMaxLeft; // 左子树中的最长距离 int nMaxRight; // 右子树中的最长距离 char chValue; // ...
原创
2021-08-18 02:23:51
49阅读
代码清单3-3for(answer[0] = 0; answer[0] < total[number[0]]; answer[0]++) for(answer[1] = 0; answer[1] < total[number[1]]; answer[1]++) for(answer[2] = 0; answer[2] < total[number[...
原创
2021-08-18 02:24:16
36阅读
代码清单3-15// 层次遍历二叉树// root,二叉树的根节点void PrintNodeByLevel(Node* root){ for(int level=0; ; level++) { if(!PrintNodeAtLevel(root, level)) break; cout <&...
原创
2021-08-18 02:23:39
28阅读
代码清单3-16// 按层次遍历二叉树// @param// root,二叉树的根节点void PrintNodeByLevel(Node* root){ if(root == NULL) return; vector<Node*> vec; // 这里我们使用STL 中的vector来代替数组,可利用 ...
原创
2021-08-18 02:23:43
72阅读