2/22作业

1.按位置插入

void insert_pos(seq_p L,datetype value,int pos)

{

if(L==NULL)

{

printf("入参为空\n");

return;

}

if(seq_full(L))

{

printf("表已满\n");

return;

}

if(pos>L->len||pos<0)

{

printf("无法插入\n");

return;

}

for(int i=L->len-1;i>=pos;i--)

{

L->date[i+1]=L->date[i];

}

L->date[pos]=value;

L->len++;

}

void del_pos(seq_p L,int pos)

{

if(L==NULL)

{

printf("入参为空\n");

return;

}

if(seq_empty(L))

{

printf("表为空\n");

return;

}

for(int i=pos;i<L->len-1;i++)

{

L->date[i]=L->date[i+1];

}

L->len--;

}

void del(seq_p L)

{

if(L==NULL)

{

printf("入参为空\n");

return;

}

if(seq_empty(L))

{

printf("表为空\n");

return;

}

for(int i=0;i<L->len;i++)

{

for(int j=i+1;j<L->len;j++)

{

if(L->date[i]==L->date[j])

{

del_pos(L,j);

j--;

return;

}

}

}

}

#include "link_list.h"

link_p creat_head()

{

link_p L = (link_p)malloc(sizeof(link_list));

if(L==NULL)

{

printf("空间申请失败\n");

}

L->len=0;

L->next=NULL;

return L;

}

link_p creat_node(datatype data)

{

link_p new = (link_p)malloc(sizeof(link_list));

if(new==NULL)

{

printf("空间申请失败\n");

}

new->data = data;

return new;

}

void insert_head(link_p H,datatype data)

{

if(H==NULL)

{

printf("入参为空\n");

return;

}

link_p new = creat_node(data);

new->next = H->next;

H->next = new;

H->len++;

}

void insert_tail(link_p H,datatype data)

{

if(H==NULL)

{

printf("入参为空\n");

return;

}

link_p new = creat_node(data);

link_p temp=H;

while(temp->next !=NULL)

{

temp=temp->next;

}

temp->next=new;

H->len++;

}

void out_put(link_p H)

{

if(H==NULL)

{

printf("入参为空\n");

return;

}

while(H != NULL)

{

if(H->next != NULL)

{

printf("%d\n",H->data);

}

else

{

printf("%d\n",H->data);

}

H=H->next;

}

}

相关推荐
No0d1es2 分钟前
电子学会青少年软件编程(C/C++)5级等级考试真题试卷(2024年6月)
c语言·c++·算法·青少年编程·电子学会·五级
Java小白程序员22 分钟前
Spring Framework :IoC 容器的原理与实践
java·后端·spring
小小愿望40 分钟前
前端无法获取响应头(如 Content-Disposition)的原因与解决方案
前端·后端
小小愿望41 分钟前
项目启功需要添加SKIP_PREFLIGHT_CHECK=true该怎么办?
前端
烛阴1 小时前
精简之道:TypeScript 参数属性 (Parameter Properties) 详解
前端·javascript·typescript
xuTao6671 小时前
Easy Rules 规则引擎详解
java·easy rules
海上彼尚2 小时前
使用 npm-run-all2 简化你的 npm 脚本工作流
前端·npm·node.js
m0_480502642 小时前
Rust 入门 KV存储HashMap (十七)
java·开发语言·rust
大阳1232 小时前
线程(基本概念和相关命令)
开发语言·数据结构·经验分享·算法·线程·学习经验
杨DaB2 小时前
【SpringBoot】Swagger 接口工具
java·spring boot·后端·restful·swagger