Home > Back-end >  The related problems of linear table for old elder brothers help online urgently
The related problems of linear table for old elder brothers help online urgently

Time:09-19

# include
# include
# include
# define LIST_INIT_SIZE 100
# define LISTINCREMENT 10
# define ElemType char
# define int Status
# define OVERFLOW - 2
# define the ERROR 0
# define OK 1
Typedef struct {
ElemType * elem;
int length;
Int listsize;
} SqList;
The Status InitList_Sq (SqList & amp; L) {
L.e lem=(ElemType *) malloc (LIST_INIT_SIZE * sizeof (ElemType));
if(! L.e lem) exit (OVERFLOW);
L.l ength=0;
L.l istsize=LIST_INIT_SIZE;
Return OK;
}//initializes the
The Status Build (SqList & amp; L)//set up table
{
Int I, n;
Printf (" please enter the number of elements n and n elements \ n ");
The scanf (" % d ", & amp; n);
If (n> LIST_INIT_SIZE)//if n is greater than the current space
{
L.e lem=(ElemType *) realloc (L.e lem, (n + LISTINCREMENT) * sizeof (ElemType));
if(! L.e lem) exit (OVERFLOW);
L.l istsize=n + LISTINCREMENT;
}
for(i=0; iThe scanf (" % d ", L.e lem + I);
L.l ength=n;
Return OK;
}//set up table
The Status ListInsert_Sq (SqList & amp; L, int I ElemType e) {
Newbase char * and * q, * p;
If (i<1 | | i> L.l ength + 1) return the ERROR;
If (L.l ength>=L.l istsize) {
Newbase=(ElemType *) realloc (L.e lem, (L.l istsize + LISTINCREMENT) * sizeof (ElemType));
if(! Newbase) exit (OVERFLOW);
L.e lem=newbase;
L.l istsize +=LISTINCREMENT;
}
Q=& amp; (L.e lem] [I - 1);
For (p=& amp; (L.e lem [L.l] ength - 1); p>=q; - * (p + 1)=p) * p;
* q=e;
+ + L.l ength;
Return OK;
}//insert
The Status ListDelete_Sq (SqList& L, int I ElemType & amp; E) {
Char * p * q;
If ((i<1) | | (i> L.l ength)) return the ERROR;
P=& amp; (L.e lem] [I - 1);
E=* p;
Q=L.e lem + L.l ength - 1;
For (+ + p; P<=q; * (p + + p) - 1)=* p;
- L.l ength;
Return OK;
}//delete
The Status DestroyList (SqList & amp; L) {
If (L.e lem) free (L.e lem);
Printf (" complete list of memory destroy \ n ");
Getch ();
system("cls");
}//destroy operation
The Status ClearList (SqList & amp; L) {
if (! L.e lem)
Return the ERROR;
L.l ength=0;
Return OK;
}//reset operation
The Status ListEmpty SqList (L) {
If (L.e lem> 0)
Printf (" order list is empty \ n ");
The else
Printf (" sequence table is for empty \ n ");

}//judging table empty
The Status ListLength SqList (L) {
int i;
for(i=0; iPrintf (" % d ", I);

}//meter long
The Status GetElem (SqList L, int I ElemType& E) {

If (i<0 | | i> L.l ength)
Return the ERROR;
E=L.e lem [I - 1);
Printf (" the ith element is: % s ", e);

}//find the position of the element and the return value I
ElemType Status LocateElem (SqList L, e) {
int i=0;
While (i<=L.l ength) {
If (L.e lem [I]==e)
break;
The else
i++; }
If (i<=L.l ength) return the I;
return 0;
}//look for the element position without return 0
Status: Print (SqList & amp; L) {
int i;
for(i=0; iPrintf (" % d ", * (L.e lem + I));
}//output sequence table
Void menu () {
Printf (" \ n \ n \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ n \ \ t t * * ");
Printf (" \ n \ \ t t * * ");
Printf (" \ \ t t * 1, destroy the order table * \ n ");
Printf (" \ \ t t * 2, judging table empty * \ n ");
Printf (" \ \ t t * 3, inventory long * \ n ");
Printf (" \ \ t t * 4, insert element * \ n ");
Printf (" \ t \ t * 5, remove elements * \ n ");
Printf (" \ \ t t * 6, empty sequence table * \ n ");
Printf (" \ t \ t * 7, take order table specify the location of the element * \ n ");
Printf (" \ \ t t * 8, the output sequence table * \ n ");
Printf (" \ t \ t * 9, look for the element location * \ n ");
Printf (" \ \ t t * 10, view menu * \ n ");
Printf (" \ t \ t * 0, exit the program * \ n ");
Printf (" \ n \ \ t t * * ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * according to the meaning of key into system * * * * * * * * * * * * \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Getch ();
system("cls");
}
Void Welcome () {

Printf (" \ n \ n \ n \ n \ n \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ n \ \ t t * * ");
Printf (" \ t \ t * the order of the linear table operation * \ n ");
Printf (" \ n \ \ t t * * ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * according to the meaning of key into system * * * * * * * * * * * * \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Getch ();
system("cls");

}

Int main () {
Int I, x, CMD;
SqList L;
ElemType e;
System (" color 1 d ");
Welcome ();
The menu ();
Build (& amp; L);
For (;; )
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related