顺序表 (头删 尾删 清空)

//头删                                                  |  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     //位置合理性判断          

思维导图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值