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;

}

}

相关推荐
香蕉鼠片1 分钟前
数据结构八股(一)
数据结构·算法
码云之上4 分钟前
从一个截图函数到一个 npm 包——pdf-snapshot 的诞生记
前端·node.js·github
Mr_Xuhhh13 分钟前
从理论到实践:深入理解算法的时间与空间复杂度
java·开发语言·算法
望眼欲穿的程序猿19 分钟前
Vscode Clangd 无法索引 C++17 或者以上标准
java·c++·vscode
6Hzlia26 分钟前
【Hot 100 刷题计划】 LeetCode 42. 接雨水 | C++ 动态规划与双指针题解
c++·算法·leetcode
带刺的坐椅29 分钟前
Spring-AI 与 Solon-AI 深度对比分析报告
java·spring·ai·llm·solon·spring-ai·solon-ai
码事漫谈34 分钟前
AI提效,到底能强到什么程度?
前端·后端
IT_陈寒35 分钟前
React hooks依赖数组这个坑差点把我埋了
前端·人工智能·后端
爱码少年37 分钟前
JAVA获取客户端真实IP地址经典写法与Lambda写法对比
java
地平线开发者37 分钟前
智能驾驶感知算法的演进
算法·自动驾驶