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;

}

}

相关推荐
uppp»1 分钟前
深入理解 Java 反射机制:获取类信息与动态操作
java·开发语言
小赵起名困难户1 小时前
蓝桥杯备赛1-2合法日期
算法
shichaog1 小时前
腿足机器人之八- 腿足机器人动力学
算法·机器人
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
ew452182 小时前
ElementUI表格表头自定义添加checkbox,点击选中样式不生效
前端·javascript·elementui
suibian52352 小时前
AI时代:前端开发的职业发展路径拓宽
前端·人工智能
Moon.92 小时前
el-table的hasChildren不生效?子级没数据还显示箭头号?树形数据无法展开和收缩
前端·vue.js·html
垚垚 Securify 前沿站2 小时前
深入了解 AppScan 工具的使用:筑牢 Web 应用安全防线
运维·前端·网络·安全·web安全·系统安全
悄悄敲敲敲3 小时前
C++:dfs习题四则
c++·算法·深度优先
m0_748256144 小时前
SpringBoot
java·spring boot·后端