#include<stdio.h> #include<math.h> // #define 定义一个标识符来表示一个常量 #define OK 1 #
define ERROR -1 #define MAX_SIZE 100 // typedef 关键字来定义自己习惯的数据类型名称 typedef int
Status; typedef int ElemType ; // struct 结构体 typedef struct sqlist{ // 定义一个数组
ElemType Elem_array[MAX_SIZE] ; // 数组的长度 int length ; } SqList ; // 删除指定元素的值
StatusLocate_Delete_SqList(SqList *L,ElemType x) /* 删除线性表L中值为x的第一个结点 */ { int i=
0 , k ; // 从数组第一个元素开始查找值为x的数组元素 while (i<L->length) /*查找值为x的第一个结点*/ { // 没找到索引+1
if (L->Elem_array[i]!=x ) i++ ; //
找到了,标记索引为i的数组元素,将索引为i的替换为索引为i+1的值,以此类推。后面元素往前移。 else { for ( k=i+1; k< L->length
; k++) L->Elem_array[k-1]=L->Elem_array[k]; L->length--; break ; } } if (i>L->
length){ printf("要删除的数据元素不存在!\n") ; return ERROR ; } // 返回删除后的数组 return L; }

技术
今日推荐
PPT
阅读数 106
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信