顺序表 (头删 尾删 清空)

cs 复制代码
//头删                                                  |  1 #include "head.h"                                       |  1 #ifndef ww
 87 void head_del(p lp)                                     |  2 int main(int argc, const char *argv[])                  |  2 #define ww
 88 {                                                       |  3 {                                                       |  3 #include <stdio.h>
 89     if(lp==0)                                           |  4     p lp=create_list();                                 |  4 #include <string.h>
 90     {                                                   |  5     int num1=empty_list(lp);                            |  5 #include <stdlib.h>
 91         printf("入参为空\n");                           |  6     if(num1==1)                                         |  6 #define max 7
 92         return;                                         |  7     {                                                   |  7 typedef struct list
 93     }                                                   |  8         printf("参数为空\n");                           |  8 {
 94     if(empty_list(lp))                                  |  9     }                                                   |  9     int arr[max];
 95     {                                                   | 10     else                                                | 10     int len;
 96         printf("参数为空无需删除\n");                   | 11         printf("参数不为空\n");                         | 11 }list,*p;
 97         return;                                         | 12     head_insert(lp,10);                                 | 12 
 98     }                                                   | 13     head_insert(lp,20);                                 | 13 //创建
 99     //元素循环前移覆盖                                  | 14     head_insert(lp,30);                                 | 14 p create_list();
100     for(int i=1;i<lp->len;i++)                          | 15     head_insert(lp,40);                                 | 15 //判空
101     {                                                   | 16     head_insert(lp,50);                                 | 16 int empty_list(p lp);
102         lp->arr[i-1]=lp->arr[i];                        | 17     head_insert(lp,60);                                 | 17 //判满
103     }                                                   | 18     end_insert(lp,100);                                 | 18 int full_list(p lp);
104     lp->len--;                                          | 19     head_del(lp);                                       | 19 //头插
105 }                                                       | 20     tail_del(lp);                                       | 20 void head_insert(p lp,int n);
106 //尾删                                                  | 21     clear_list(lp);                                     | 21 //输出
107 void tail_del(p lp)                                     | 22     show(lp);                                           | 22 void show(p lp);
108 {                                                       | 23     return 0;                                           | 23 //尾插
109     if(lp==0)                                           | 24 }                                                       | 24 void end_insert(p lp,int n);
110     {                                                   |~                                                           | 25 //头删
111         printf("入参为空\n");                           |~                                                           | 26 void head_del(p lp);
112         return;                                         |~                                                           | 27 //尾删
113     }                                                   |~                                                           | 28 void tail_del(p lp);
114     if(empty_list(lp))                                  |~                                                           | 29 //清空
115     {                                                   |~                                                           | 30 void clear_list(p lp);                                                                                     
116         printf("参数为空无需删除\n");                   |~                                                           | 31 
117         return;                                         |~                                                           | 32 
118     }                                                   |~                                                           | 33 
119     lp->len--;                                          |~                                                           | 34 
120 }                                                       |~                                                           | 35 
121 //按位置插入                                            |~                                                           | 36 
122 void insert_pos(p lp,int n,int pos)                     |~                                                           | 37 #endif
123 {                                                       |~                                                           |~                                                                                                              
124     if(lp==0)                                           |~                                                           |~                                                                                                              
125     {                                                   |~                                                           |~                                                                                                              
126         printf("入参为空\n");                           |~                                                           |~                                                                                                              
127         return;                                         |~                                                           |~                                                                                                              
128     }                                                   |~                                                           |~                                                                                                              
129     if(full_list(lp))                                   |~                                                           |~                                                                                                              
130     {                                                   |~                                                           |~                                                                                                              
131         printf("表已满无法插入");                       |~                                                           |~                                                                                                              
132     }                                                   |~                                                           |~                                                                                                              
133     //位置合理性判断          

思维导图:

相关推荐
帅得不敢出门4 小时前
macOS苹果电脑运行向日葵远程控制软件闪退
windows·macos·远程控制·向日葵
索迪迈科技10 小时前
记一次 .NET 某中医药附属医院门诊系统 崩溃分析
windows·c#·.net·windbg
十八旬10 小时前
苍穹外卖项目实战(day7-2)-购物车操作功能完善-记录实战教程、问题的解决方法以及完整代码
java·开发语言·windows·spring boot·mysql
Clownseven15 小时前
阿里云ECS安装Windows Server 2022教程 | 纯文字分步指南
windows·阿里云·云计算
T0uken15 小时前
【C++】LLVM-mingw + VSCode:Windows 开发攻略
c++·windows·vscode
能摆一天是一天1 天前
JAVA stream().flatMap()
java·windows
JosieBook1 天前
【远程运维】Linux 远程连接 Windows 好用的软件:MobaXterm 实战指南
linux·运维·windows
该用户已不存在1 天前
你没有听说过的7个Windows开发必备工具
前端·windows·后端
枫叶落雨2221 天前
注解参数校验
windows