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;

}

}

相关推荐
谎言西西里17 小时前
LeetCode 热题100 --- 双指针专区
算法
喝拿铁写前端18 小时前
别再让 AI 直接写页面了:一种更稳的中后台开发方式
前端·人工智能
五岳19 小时前
分库分表数据源ShardingSphereDataSource的Connection元数据误用问题分析
java·mysql·爬坑
带刺的坐椅19 小时前
迈向 MCP 集群化:Solon AI (支持 Java8+)在解决 MCP 服务可扩展性上的探索与实践
java·ai·llm·solon·mcp
鼠爷ねずみ19 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中
java·数据库·后端·spring·spring cloud
A向前奔跑19 小时前
前端实现实现视频播放的方案和面试问题
前端·音视频
代码or搬砖19 小时前
String字符串
android·java·开发语言
十一.36619 小时前
131-133 定时器的应用
前端·javascript·html
leo__52020 小时前
基于两步成像算法的聚束模式SAR MATLAB实现
开发语言·算法·matlab