0.线性表
1.定义
线性表就是零个或多个相同数据元素的有限序列。
2.线性表的存储结构
①.顺序结构

②.链式结构
3.线性表的表示方法

例如:

一.线性表的基本运算


二.线性表的复杂运算
1.线性表的合并运算

2.线性表的去重运算

三.顺序表
1.定义
顺序表,就是线性表的顺序存储格式

2.顺序表的实现

①.顺序表的创建

/**
 * @description:            创建一个新的顺序表
 * @param       :           无
 * @return      :           创建的顺序表的指针
*/
seqlist_t *create_seqlist(void)
{
    seqlist_t *L = NULL;
    /* 1.申请空间 */
    L = (seqlist_t *)malloc(sizeof(seqlist_t));
    if(NULL == L)
    {
        printf("malloc seqlist_t *L faild error!\n");
        return NULL;
    }
    /* 初始化顺序表内部指针的位置 */
    L->last = -1;
    return L;
} 
②.置空顺序表

/**
 * @description:        清空顺序表内的数据
 * @param - L   :       要操作的顺序表
 * @return      :       无
*/
void set_empty_seqlist(seqlist_t *L)
{
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return ;
    }
    L->last = -1;
}    
③.释放顺序表
/**
 * @description:       释放一个顺序表
 * @param L    :       要释放的顺序表的指针
 * @return     :       无
*/
void clear_seqlist(seqlist_t * L)
{
    /* 1.首先判断传入的顺序表是否有效 */
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return ;
    }
    /* 若有效,则释放该表 */
    free(L);
} 
④.判断顺序表是否满/是否空

/**
 * @description:                  判断顺序表是否为满
 * @param L         :             要进行判断的顺序表
 * @return          :             1 为满 ,其他 为非满
*/
int is_full_seqlist(seqlist_t *L)
{
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return -1;
    }
    return (L->last == MAXSIZE - 1);
} 
/**
 * @description:            判断顺序表是否为空
 * @param - L       :       要操作的顺序表
 * @return          :       1 为空,其他 为非空
*/
int is_empty_seqlist(seqlist_t *L)
{
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return -1;
    }
    return (L->last == -1);
} 
⑤.向顺序表插入一个元素

/**
 * @description:            向顺序表中指定位置前插入一个数据
 * @param L         :       要进行操作的顺序表
 * @param x         :       要插入的值
 * @param pos       :       要插入的位置
 * @return          :       0 成功, 其他 失败
*/
int insert_seqlist(seqlist_t *L,data_t x,int pos)
{
    int i = 0;
    /* 若顺序表已满,或者插入位置无效 */
    if(is_full_seqlist(L) || (pos < 0) || (pos > L->last +1))
    {
        printf("input argv is invalid\n");
        return -1;
    }
    /* 若pos要插入的位置为i,则从最后一个元素开始,到i的元素先依次往后移动一个位置 */
    for(i = L->last;i >= pos;i--)
    {
        L->data[i + 1] = L->data[i];
    }
    /* 将x的值赋给data[pos]位置 */
    L->data[pos] = x;
    /* 顺序表末尾的指针往后移动一个位置 */
    L->last++;
    return 0;
} 
⑥.删除指定位置的元素

/**
 * @description:            在顺序表中指定位置删除一个数据
 * @param - pos     :       指定删除的元素的位置
 * @return          :       0 成功,其他 失败
*/
int delete_seqlist(seqlist_t *L,int pos)
{
    int i = 0;
    if(pos < 0 || pos > L->last)
    {
        printf("input pos invalid\n");
        return -1;
    }
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return -1;
    }
    for(i = pos;i < L->last;i++)
        L->data[i] = L->data[i + 1];
    L->last--;
    return 0;
} 
⑦.替换顺序表中指定位置的元素
/**
 * @description:        替换顺序表中指定位置的数据
 * @param - L   :       要操作的顺序表
 * @param - x   :       输入的元素值
 * @param - pos :       要替换的元素的位置
 * @return      :       0 成功, 其他 失败 
*/
int change_seqlist(seqlist_t *L,data_t x,int pos)
{
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return -1;
    }
    if(pos < 0 || pos > L->last)
    {
        printf("input pos invalid\n");
        return -1;
    }
    L->data[pos] = x;
    return 0;
} 
⑧.找到元素X在表中第一次出现的位置

/**
 * @description:            查找指定元素在顺序表中第一次出现的位置
 * @param - L       :       要操作的顺序表
 * @param - x       :       要查找的元素
 * @return          :       x第一次出现的位置
*/
int search_seqlist(seqlist_t *L,data_t x)
{
    int i = 0;
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return -1;
    }
    for(i = 0;i <= L->last;i++)
    {
        if(L->data[i] == x)
            return i;   
    }
    return -1;
}    
⑨.打印顺序表的全部内容
/**
 * @description:        打印顺序表的所有数据
 * @param L     :       要进行操作的顺序表
 * @return      :       无
*/
void show_seqlist(seqlist_t *L)
{
    int i = 0;
    if(NULL == L)
    {
        printf("seqlist *L is NULL\n");
        return ;
    }
    for(i = 0;i <= L->last;i++)
        printf("L->data[%d] = %d\n",i,L->data[i]);
    
    return ;
}  
⑩.求顺序表长

/**
 * @description:            获取顺序表的长度
 * @param - L       :       要操作的顺序表
 * @return          :       顺序表的长度
*/
int get_length_seqlist(seqlist_t *L)
{
    if(NULL == L)
    {
        printf("seqlist_t *L is NULL\n");
        return -1;
    }
    return (L->last + 1);
} 
                

![[数据集][目标检测]井盖丢失未盖破损检测数据集VOC+YOLO格式2890张5类别](https://i-blog.csdnimg.cn/direct/31cf5cd2f3cd4257a13e5fb30d7908a0.png)
















