Home > Back-end >  Write function is removed from the incremental orderly sequence table element value between x and y
Write function is removed from the incremental orderly sequence table element value between x and y

Time:09-23

#include
#include
# define true 1
# define FALSE 0
# define OK 1
# define the ERROR 0
# define OVERFLOW - 2
# define LIST_INIT_SIZE 100
# define LISTINCREMENT 10
Typedef int the status;
Typedef int ElemType;
Typedef struct {
ElemType * elem;
int length;
Int listlize;
} SqList;
The status InitList (SqList & amp; L)//initialization sequence table
{//constructs an empty sequence table L
L.e lem=(ElemType *) malloc (LIST_INIT_SIZE * sizeof (ElemType));
if(! L.e lem) exit (OVERFLOW);
L.l ength=0;
L.l istlize=LIST_INIT_SIZE;
return OK;
}
The status CreateList (SqList & amp; L)//build order table
{
int i,j;
Printf (" please enter the order table length: \ n ");
The scanf (" % d ", & amp; J);
If (j> LIST_INIT_SIZE)//when the number of elements in the input is greater than the number of the current element
{
L.e lem=(ElemType *) realloc (L.e lem, sizeof (j + LISTINCREMENT) * (ElemType));
L.l istlize=j + LISTINCREMENT;
}
Printf (" please enter the order table elements: \ n ");
For (I=0; iThe scanf (" % d ", & amp; L.e lem [I]);
Printf (" current order table for: ");
For (I=0; iPrintf (" % d ", L.e lem [I]);
printf("\n");
L.l ength=j;
return OK;
}
The status ListDelete (SqList & amp; L, int I ElemType & amp; E)//in order to delete the element I in the table, and returns its value e
{
If ((i<1) | | (i> L.l ength)) return the ERROR;
Int * p, * q;
P=& amp; (L.e lem] [I - 1);
E=* p;
Q=L.e lem + L.l ength - 1;
For (+ + p; p<=q; + + p)
* (p=* p - 1);
- L.l ength;
return OK;
}
The status delxy (SqList & amp; L, int x, int y)
{
Int I, m, n, e, k=0;
//for (I=0; i//if (! (L.e lem [I]==x) | |! (L.e lem [I]==y)) return the ERROR;
for(i=0; i{
If (L.e lem [I]==x) m=I; break;
}
Printf (" % d ", m);
For (I=L.l ength - 1; I>=0; I -)
{
If (L.e lem [I]==y) n=I; break;
}
Printf (" % d ", n);
For (I=m + 1; K<=(n, m); K++)
ListDelete (L, I, e);
return OK;
}
Void ListTraverse (SqList L)
{
int i;
for(i=1; i<=L.l ength; I++)
Printf (" % d ", L.e lem [I - 1));
}
Int main ()
{
Int x, y;
SqList L;
InitList (L);
CreateList (L);
Printf (" please enter the x: \ n ");
The scanf (" % d ", & amp; X);
Printf (" please enter y: \ n ");
The scanf (" % d ", & amp; Y);
Delxy (L, x, y);
Printf (" delete operation to complete! The current order table for: ");
ListTraverse (L);
printf("\n");
return 0;
}
  • Related