查找字符串中字符不重复的最大子串(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;
}
相关文档:
以 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.运行环境VC6.0(Microsoft Visual C++ 6.0)(http://40.duote.org/microsoft_visualc6.zip)
2.课题相关内容:AVS视频编码
二、出现的问题及解决方法:
1.问题:
fatal er ......
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/wait.h>
#define QLEN 20
# ......
数组是类型相同的对象的序列,其中的对象称为数组元素。也可以将数组想像成一连串的用下标值编号的相邻存储区。
可能在某些编程语言中,一个下标变量是不允许超出数组定义中所设的界限的。但是在C和C++中,数组是没有这种安全措施的。下面先来看看数组下标越界的几种异常结果。
&nb ......