Home > database >  O great god answer (for what so many mistakes)
O great god answer (for what so many mistakes)

Time:10-19

to establish an orderly sequence table, and implement the following operations:
1. Insert the element x in the table and keep orderly; 2. To find the value of x element, if found deleted;
3. The output value of each element in the table
# define MAXSIZE 100
# define OK 1
# define the ERROR 0
#include
Typedef int ElemType
Typedef struct
{
ElemType elem [MAXSIZE];//linear table takes an array of space
Int last;//record the last element in the array in linear table elem [] the position (values), empty table set to 1.
}SeqList; 3
Int Inslist (SeqList * L, ElemType e)//insert element
{
int i;
If ((i<1 | | (i> L - & gt; The last + 2))
{
Printf (" insert position illegal! \n");
Return (ERROR);
}
If (L - & gt; The last=MASIZE - 1)
{
Printf (" table is full, can't insert \ n ");
Return (ERROR);
}
For (I=L - & gt; last; i>=0 & amp; & EL - & gt; Elem [I + 1)=L - & gt; Elem [I];
L - & gt; Elem [I + 1)=e;
L - & gt; Last++;
return OK;
}
Int DelList (SeqList * L, ElemType e)//search element and remove
{
Int k, I;
K=0;
While (k<=L - last& & L - & gt; Elem [k]!=e)
K++;
If (k<=l - & gt; The last)
{
For (I=k + 1; i<=L - & gt; last; I++)
L - & gt; Elem] [I - 1=l - & gt; Elem [I];
L - & gt; Last -;
return OK;
}
The else
Printf (" this element is not in the table! \n");
return ERROR;
}
Void the output (SeqList * L)//output element
{
int i;
for (i=0; i{
Printf (" % d ", L.e lem [I]);
}
Printf (" \ n ");
}
Void main ()
{
SeqList * list, the list 1;
Int I, n, m;
List=& amp; List 1;
Printf (" please input data: \ n ");
The scanf (" % d ", & amp; n);
for(i=0; iThe scanf (" % d ", & amp; The list - & gt; Elem [I]);
The list - & gt; The last=n - 1;
The output (list);
Printf (" please enter to insert value: \ n ");
The scanf (" % d ", & amp; M);
The InList (list, m);
The output (list);
Printf (" please enter a value to delete: \ n ");
The scanf (" % d ", & amp; M);
DelList (list, m);
The output (list);
}

CodePudding user response:

First typedef line haven't missing semicolon, behind a definition semicolon a 3 below, the original poster carefully check again carefully, don't let us be your surprise surprise
  • Related