Table 6-2 interval linear elements deleted

A given sequence to the linear table store, designed to function deletes all values ​​greater than a min and max is less than the element. After deleting the table holding the remaining elements are sequentially stored, and the relative position can not be changed.

Function interface definition:
List the Delete (List L, the ElementType minD, the ElementType maxD);

Wherein List structure is defined as:

int the Position typedef;
typedef struct LNode List;
struct {LNode
the ElementType the Data [the MAXSIZE];
the Position Last; /
save the last element of the linear table * /
};

L is a linear incoming user table, which elements can ElementType>, ==, <comparing; minD and maxD range to be deleted are lower element, the upper bound. Delete All function values ​​should be the Data [] is greater than and less than maxD minD delete elements, while ensuring that the remaining elements of the table holding sequentially stored, and the same relative position, and finally return to the table after the deletion.

Referee test sample program:
#include <stdio.h>

#define MAXSIZE 20
typedef int ElementType;

int the Position typedef;
typedef struct LNode List;
struct {LNode
the ElementType the Data [the MAXSIZE];
the Position Last; /
save the last element of the linear table * /
};

List ReadInput (); / * referee realized, not the details of the table. From zero element index storage /
void printlist (List L); /
ref achieved, not the details of the table * /
List the Delete (List L, the ElementType minD, the ElementType maxD);

int main()
{
List L;
ElementType minD, maxD;
int i;

L = ReadInput();
scanf("%d %d", &minD, &maxD);
L = Delete( L, minD, maxD );
PrintList( L );

return 0;

}

/ * Your code will be embedded here * /

Sample input:
10
. 4. 9. 5. 1 12 is 2 -8. 3 10. 3
0. 4

Output Sample:
4-8125910

List Delete( List L, ElementType minD, ElementType maxD )
{
    int i=0,j=0;
    for(i=0;i<=L->Last;i++)
    {
        if(L->Data[i]>=maxD||L->Data[i]<=minD)
        {
                L->Data[j++]=L->Data[i];
        }
    }
    L->Last=j-1;//值得注意,走一遍就知道啦
    return L;
}
Published 33 original articles · won praise 4 · Views 3054

Guess you like

Origin blog.csdn.net/qq_45728926/article/details/104991438