| 40 | |
| 41 | |
| 42 | bool ListDelete(SqList &L, int i, ElemType &e){ |
| 43 | |
| 44 | // i非法 i=1 表头 i=L.length+1 表尾巴 |
| 45 | if(i<1||i>L.length+1){ |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // 存储空间满,无法插入 |
| 50 | if(L.length >= MaxSize){ |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | // 引用变量e赋值 |
| 55 | e=L.data[i-1] |
| 56 | |
| 57 | // 遍历,第i个元素后面的往前移动 |
| 58 | for(int j=i; j<=L.length;j++){ |
| 59 | // 从第i个元素开始,角标从i-1开始 |
| 60 | L.data[j-1]=L.data[j]; |
| 61 | } |
| 62 | |
| 63 | // 此时,表L中的表尾元素和倒数第二个元素值一样,将表的长度-1 |
| 64 | |
| 65 | // 表长度减1 |
| 66 | L.length--; |
| 67 | |
| 68 | // 返回删除成功 |
| 69 | return true; |
| 70 | } |
nothing calls this directly
no outgoing calls
no test coverage detected