数据结构(C语言版)课后习题,求大佬解答?

编写算法,实现下面函数的功能。函数void insert(char*s,char*t,int pos)将字符串t插入到字符串s中,插入位置为pos。假设分配给字符串s的空间足够让字符串t插入。(说明:不得使用任何库函数)

#include<stdio.h>

void f(char *s,char *ss,int n) { int i,k,m; char *p,*q,*r;

k=0; r=ss; while ( *r ) { r++;  k++; } //找到ss的末尾0,计算ss长度

m=0; q=s; while ( *q ) { q++; m++; } //找到s的末尾0

p=q; q+=k; *q=0; q--; //计算新字符串结尾位置

for ( i=0;i<m-n;i++,p--,q-- ) *q=*p; //将s最后k个字符后移k位

for ( i=0,r--;i<k;i++,q--,r-- ) *q=*r; //将ss倒序复制到s中空出来位置

}

void main() { char s[256],ss[256]; int n;

scanf("%s%s%d",s,ss,&n); f(s,ss,n); printf("%s\n",s);

}

温馨提示:答案为网友推荐,仅供参考