查找字符串中字符不重复的最大子串(C/C++)
//输入参数:*str 搜索字符串
// subStrLen 用于返回找到的最大子字符串长度
//返回:找到的最大子字符串指针
char * findMaxSubStr(char *str, int &subStrLen){
char *subStr;
char *p = str;
int index[256] ;
for (int ix = 0; ix < sizeof(index)/sizeof(index[0]); ix++)
{
index[ix] = -1;
}
int subStrPos = 0; // 子字符串在字符串str中的偏移
int charPos = 0; // 当前字符在字符串str中的偏移
int currLen = 0; //当前子字符串长度
int maxLen = 0; //已经找到的最大子字符串长度
char ch;
while (ch = *p)
{
if (index[ch] < subStrPos){ //字符首次出现 或者 字符在子字符串开始的位置后首次出现
index[ch] = charPos;
currLen++;
}else {
currLen = charPos - index[ch];
subStrPos = ++index[ch];
index[ch] = charPos;
}
if (currLen > maxLen)
{
subStr = str + subStrPos;
maxLen = currLen;
}
p++;
charPos++;
}
subStrLen = maxLen;
return subStr;
}
相关文档:
源程序编译
Makefile的编写
程序库的链接
程序的调试
头文件和系统求助
1.源程序的编译
在Linux下面,如果要编译一个C语言源程序,我们要使用GNU的gcc编译器. 下面我们以一个实例来说明如何使用gcc编译器.
......
以 i2c-mpc.c 驱动模块为例
fsl_i2c_init -> of_register_platform_driver -> of_register_driver -> driver_register -> bus_add_driver -> driver_attach
-> bus_for_each_dev -> __driver_attach -> driver_probe_device -> really_probe -> drv->probe(dev); ......
9.2 共用体
C语言除了提供结构体这种可包含多种类型数据的构造类型外,还提供了一种从形式上看和结构体堪称“孪生兄弟”的构造类型——共用体(union)。
本节从共用体的概念入手,从共用体的概念、与结构体的异同、使用等方面进行详细的介绍。
9.2.1 什么是共用体
现实生活中,某些事 ......
1. 什么是空指针常量(null pointer constant)?
[ 6.3.2.3-3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
这里告诉我们:0、0L、'\0'、3 - 3、0 * 17 (它们都是“integer constant expression”)以及 ......
一、屏幕操作函数
1. clrscr()清除字符窗口函数
2. window()字符窗口函数
3. gotoxy()光标定位函数
4. clreol() 清除光标行尾字符函数
5. insline() 插入空行函数
6. delline() 删除一行函数
7. gettext() 拷进文字函数
8. puttext() 拷出文字函数
9. movetext() 移动文字函数
二、字符属性函数
10. textmode( ......