Delete element of C language sequence table

#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 ;

// 删除元素,传参:结构体指针,删除第几个数
ElemType  Delete_SqList(SqList *L,int i){
    
      
    int  k ;   ElemType  x ;
    if  (L->length==0){
    
    
          printf("线性表L为空!\n"); 
          return ERROR;  
    } 
    else if ( i<1||i>L->length ) {
    
    
        printf("要删除的数据元素不存在!\n") ; 
        return ERROR ; 
    }
    else{
    
    
        x=L->Elem_array[i-1] ;   /*保存结点的值*/
        for ( k=i ;  k<L->length ; k++) 
            L->Elem_array[k-1]=L->Elem_array[k];
                    /*  i位置以后的所有结点前移  */
        L->length--;  
        return L;
    }
} 

Guess you like

Origin blog.csdn.net/weixin_46073538/article/details/114226077