顺序表中删除值在X--Y之间的元素

/*从给定的顺序表中删除值在X--Y之间的元素*/
/*已知线性表中的元素以值递增有序排列,并以单链表作存储结构。试写一高效算法,删除表中所有值大于mink且小于maxk的元素*/
#include
#define  ElemType  int;
#define LIST_SIZE 100
typedef struct {
       int *elem;
         int length;
         }Sqlist;
    void InitList(Sqlist *L)
    {
      (*L).elem=(int *)malloc(LIST_SIZE*sizeof(int));
         if( !(*L).elem )
         exit(1);
      }  
   void Delete(Sqlist *L,int X,int Y)
     {
          int i=0,n=0;
         while(i<(*L).length) 
             {
                 if((*L).elem[i]>=X && (*L).elem[i]<=Y)
                  n++;                          
                  else
                  (*L).elem[i-n]=(*L).elem[i];
                  i++;
             }
             (*L).length-=n;
             if((*L).length==0)
             printf("the sqlist ie empty/n");   
     }      
                            
         
int main()
{
          int X,Y,i;
          Sqlist A;          
            InitList(&A);   

          printf("please input the length :/n");
          scanf("%d",&A.length);
          printf("please input the elem :/n");
          for(i=0;i          scanf("%d",&A.elem[i]);
          printf("please input X ,Y :/n");
          scanf("%d%d",&X,&Y);
         Delete(&A,  X,  Y);    
          printf("the result list :/n");
           for(i=0;i           printf("%3d",A.elem[i]);
           return 0; 
}
          
 

你可能感兴趣的:(算法&&我的程序,input,delete,list,struct,算法,存储)