请问大家:急!!!!!!!!真的很急,谢谢了
//还没有弄清楚,具体的在做标记处
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
#define NULL 0
typedef struct node {
int num;
struct node *link;
}NODE;
NODE *create(NODE *h){
//创建一个字符串,返回头结点
char c;
NODE *p,*q;
h=(NODE *)malloc(sizeof(NODE));
h->num=0;
h->link=NULL;
q=h;
printf("input character\n");
while((c=getchar())!='\n'){
++h->num;
p=(NODE *)malloc(sizeof(NODE));
p->link=NULL;
q->link=p;
p->num=c;
q=p;
}
return h;
}
NODE *subs(NODE *h,int pos,int n){
//取出串中指定位置开始的若干字符
NODE *p,*q,*h1,*m;
int i=0;
if((pos+n-1)>h->num){
printf("error\n");//至此,程序正确
return NULL;//返回是否错误?????????
}//取出的字符数多与字符串中的字符数
else{
while(i<pos){
q=p;
p=p->link;
++i;
}
m=p;
i=0;
h1=(NODE *)malloc(sizeof(NODE));
h1->num=n;
h1->link=NULL;
q=h1;//取出字符串的头结点
while(i<n){
++i;
p=(NODE *)malloc(sizeof(NODE));
p->num=m->num;
p->link=NULL;
q->link=p;
q=p;
m=m->link;
}
return h1;
}
}
NODE *insert(NODE *h,NODE *h1,int pos){
int i=0;
NODE *p,*q;
p=h;
while(i<(pos-1)){
++i;
p=p->link;
}
q=p->link;
p->link=h1->link;
h->num=h1->num+h->num;
while(h1->link!=NULL)
h1=h1->link;
h1->link=q;
free(h1);
return h;
}
int ddelete(NODE *h,int pos,int n){
//成功删除,返回0;否则返回-1
int i=0;
NODE *p,*q,*m;
if((pos+n-1)>h->num)
return -1;
if(n==0)
return 0;
while(i<pos-1){
++i;
p=p->link;
}
q=p;
i=1;
p=p->link;
while(i<n){
++i;
m=p;
p=p->link;
free(m);
}
q->link=p->link;
free(p);
h->num=h->num-n;
return 0;
}
int position(NODE *h,NODE *h1){//该函数在找不到指定串时正常运行,如果串
//能找到,运行时会发生非法操作
//串匹配,如不存在,返回-1;存在,返回所在位置POS
NODE *p,*q,*m;
int pos=1;
p=h->link;
q=h1->link;
while(p->num!=q->num){
p=p->link;
++pos;
}
m=p;
while(p!=NULL&&((pos+h1->num-1)<h->num)){
while(p->num==q->num&&p!=NULL&&q!=NULL){//该出语句出错
p=p->link;
q=q->link;
}
if(p==NULL&&q!=NULL)
return -1;
else if(q==NULL)
return pos;
++pos;
p=m->link;
m=m->link;
q=h1->link;
}
return -1;
}
int main(){
long int w=1,pos,n;
char a,c;
NODE *h,*h1,*p,*q;
while(w){
printf("create a string\nplease input Y/N\n");
a=getchar();
if(a=='y'||a=='Y'){
getchar();
h=create(h);
w=0;
}
if(a=='n'||a=='N')
exit(1);
}
while(a!='5'){
printf("Get part of the string? If you want to do so,please input 1;\nFind part of the string? If you want to do so,please input 2;\nInsert another string? If you want to do so,please input 3;\nDelete part of the string? If you want to do so,please input 4;\nExit? If you want to do so,please input 5.\n");
a=getchar();
getchar();//用来消除ENTER键
switch(a){
case '1':{
printf("input the position of the string you want to get\n");
scanf("%d",&pos);
printf("input the number of the string you want to get\n");
scanf("%d",&n);
p=subs(h,pos,n);
if(p=NULL){
printf("heliangliang\n");// 当返回 NULL时,该语句没有被执行,该语句没作用,仅来检测是否被执行
break;
}
else{
printf("%d",p->num);
printf("the following is the string you want to get:\n");
p=p->link;
while(p!=NULL){
p=p->link;
printf("%c",p->num);
}
printf("\n");
break;
}
}
case '2':{
printf("Please input the string you want to find\n");
h1=(NODE *)malloc(sizeof(NODE));
h1->num=0;
h1->link=NULL;
q=h1;
while((c=getchar())!='\n'){
++h1->num;
p=(NODE *)malloc(sizeof(NODE));
p->link=NULL;
q->link=p;
p->num=c;
q=p;
}
pos=position(h,h1);
if(pos==-1)
printf("The string cannot be found !\n");
else
printf("The string's position is %d.\n",pos);
break;
}
case '3':{
printf("Please input the string you want to insert\n");
h1=(NODE *)malloc(sizeof(NODE));
h1->num=0;
h1->link=NULL;
q=h1;
while((c=getchar())!='\n'){
++h1->num;
p=(NODE *)malloc(sizeof(NODE));
p->link=NULL;
q->link=p;
p->num=c;
q=p;
}//至此,程序正确
printf("input the position of the string where you want to insert\n");
scanf("%d",&pos);
h=insert(h,h1,pos);
p=h->link;
printf("The new string which you have inserted another string is as follows:\n");
while(p!=NULL){
printf("%c",p->num);
p=p->link;
}
printf ("\n");
break;
}
case '4':{
printf("Please input the position where you want yo delete\n");
scanf("%d",&pos);
printf("Please input the number of chars of the string you want to delete\n");
scanf("%d",&n);
if(ddelete(h,pos,n))
printf("There is something error that cannot delete the string you offer successfully\n");
else{
printf("The new string is as follows: \n");
p=h->link;
while(p!=NULL){
printf("%c",p->num);
p=p->link;
}
printf("\n");
}
break;
}
case '5': exit(1);
}
}
return 0;
}
相关推荐
工业互联网工控安全与工业质检AI大模型建设方案.pptx
工业互联网工控安全与工业质检AI大模型建设方案.pptx
2024 《计算机网络》实验教学指导书.doc
2024 《计算机网络》实验教学指导书.doc
不平衡电网下自抗扰顺序模型预测PWM整流器控制仿真模型(Simulink仿真实现)
内容概要:本文围绕面向城市空中交通的多无人机路径规划问题展开研究,提出了一套融合全局规划、动态避障与局部协同调整的综合路径规划方法。研究内容涵盖基于改进RRT算法与图论的全局路径规划、基于动态风险场和动态窗口法(DWA)的模型预测控制实现动态避障,以及基于分布式协同控制的多无人机局部路径协同策略。通过Matlab平台构建仿真环境,在多种典型城市交通场景下对所提方法进行了系统性验证,结果表明该方法在路径安全性、编队稳定性与任务效率方面表现优异。文章还深入探讨了算法的创新点与未来研究方向,为复杂城市环境下多无人机系统的自主协同提供了理论支撑与技术路径。; 适合人群:具备自动化、控制理论、计算机科学或相关领域基础知识,从事无人机系统、智能交通、路径规划、多智能体协同控制等方向研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①为城市空中交通系统中的多无人机安全、高效飞行提供可靠的路径规划解决方案;②支持在复杂、动态的城市场景中开展无人机自主导航、编队飞行与协同控制的技术研究与仿真验证。; 阅读建议:建议结合提供的Matlab代码进行实践操作,重点关注算法的具体实现细节、参数配置对性能的影响以及不同仿真场景下的实验设计,以深入理解各模块的集成逻辑与实际应用效果。
通信行业CentOS 7内核网络栈优化:高并发连接下UDP/TCP性能调优与系统资源管理
内容概要:本文聚焦于CentOS 7系统在通信行业高并发场景下的性能调优实践,重点围绕内核网络栈优化展开,涵盖UDP/TCP缓冲区调整、文件句柄与连接跟踪表扩容、TIME_WAIT状态复用、软中断分布优化及tuned工具的自动化调优。通过具体配置参数和实际案例(如VoIP软交换系统)深入解析各项调优措施的设计原理与实施效果,有效解决高CPS下丢包、连接失败等问题,并展望了向云化、eBPF等动态智能调优方向的发展趋势。; 适合人群:从事通信系统运维、网络开发或Linux系统性能优化的技术人员,具备一定操作系统和网络基础知识,工作经验1年以上的中初级工程师。; 使用场景及目标:①应用于软交换、媒体网关、信令网关等高并发通信设备的系统调优;②解决UDP丢包、conntrack表满、TCP连接队列溢出等典型性能瓶颈;③提升系统在小包高频、低时延要求场景下的稳定性和吞吐能力。; 阅读建议:建议结合实际生产环境或测试平台同步验证文中配置,重点关注参数背后的物理意义(如BDP、softirq、conntrack机制),并配合ss、conntrack、dmesg等命令进行调优前后对比分析,确保安全可控地实施变更。
利用MATLAB 4f光学系统,在Python中进行弗劳恩霍夫衍射和傅里叶面滤波——用镜头模拟光学图像处理。.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。


非技术区

