Sequential storage order table, delete all the elements of a given value between the s and t

. 1 #include <stdio.h>
 2 #include <stdlib.h>
 . 3  void del ( int * A, int & n-, int S, int T)
 . 4  {
 . 5      int I = 0 ; 
 . 6      the while (I <n-&& A [ I] <S) I ++;     // find the element value == s 
. 7      
. 8      int J = I;
 . 9      the while (J <n-&& a [J] <= T) J ++;     // find value> t the first element 
10      
. 11      for (; J <n-; J ++, ++ I)
 12 is          a [I] = a [J];        // forward, to fill the position of the deleted element 
13 is      
14      n-= I; // back to the number of elements 
15  }
 16  
. 17  int main ()
 18 is  {
 . 19      int ARR [] = { . 1 , 2 , . 3 , . 4 , . 5 , . 6 , . 7 , . 8 , . 9 , 10 };
 20 is      int n-= the sizeof (ARR) / the sizeof ( int );
 21 is      
22 is      del (ARR, n-, . 4 , . 7);
23     
24     for(int i=0; i<n; ++i){
25         printf("%d ",arr[i]);
26     }
27     return 0;
28 }

 

Guess you like

Origin www.cnblogs.com/GoldenEllipsis/p/11258792.html