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;

}

}

相关推荐
元亓亓亓36 分钟前
LeetCode热题100--230. 二叉搜索树中第 K 小的元素--中等
算法·leetcode·职场和发展
草莓熊Lotso36 分钟前
《算法闯关指南:优选算法-双指针》--01移动零,02复写零
c语言·c++·经验分享·算法·leetcode
焜昱错眩..2 小时前
代码随想录算法训练营第三十九天|62.不同路径 63.不同路径ll
算法
dy17173 小时前
element-plus表格默认展开有子的数据
前端·javascript·vue.js
float_六七4 小时前
IntelliJ IDEA双击Ctrl的妙用
java·ide·intellij-idea
能摆一天是一天5 小时前
JAVA stream().flatMap()
java·windows
焦耳加热5 小时前
阿德莱德大学Nat. Commun.:盐模板策略实现废弃塑料到单原子催化剂的高值转化,推动环境与能源催化应用
人工智能·算法·机器学习·能源·材料工程
wan5555cn5 小时前
多张图片生成视频模型技术深度解析
人工智能·笔记·深度学习·算法·音视频
颜如玉6 小时前
🤲🏻🤲🏻🤲🏻临时重定向一定要能重定向🤲🏻🤲🏻🤲🏻
java·http·源码
u6066 小时前
常用排序算法核心知识点梳理
算法·排序