- 博客(2)
- 收藏
- 关注
原创 字符串查找—朴素查找算法
设主串的下标为i,子串下标为j 算法思想:主子串下标对应的值相等,则继续向前移动比较(下标++);不相等则回退,i退到刚才位置的下一个(i-j+1),j回退到0. 时间复杂度:O(n*m) //主串长n,子串长m. //在主串str的pos位置开始查找子串sub,找到返回下标,失败返回-1 int BF(const char *str,const char *sub,int pos) { assert(str != NULL && sub != NULL); if(s
2021-10-19 23:25:13
110
原创 交换两个数的值(C语言)2021-04-22
交换两个数的值(C语言) 方法一 直接交换 代码: #include <stdio.h> int main() { int a=10; int b=20; int tmp=a; a=b; b=tmp; printf("%d,%d\n",a,b); return 0; } 运行结果: 2.方法二 使用指针 代码如下: #include <std...
2021-04-22 18:03:29
99
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人