Home > Back-end >  The compiler operation caption dev c data structure
The compiler operation caption dev c data structure

Time:11-06

 # include 
#include
# define MaxSize 50
Typedef char ElemType;
Typedef struct
{
ElemType data [MaxSize];
int length;
} SqList;
Void CreateList (SqList * & amp; L, ElemType a [], int n)
{
L=(SqList *) malloc (sizeof (SqList));
for(int i=0; iL - & gt; Data=[I] a [I];
L - & gt; Length=n;

}
Void InitList (SqList * & amp; L)
{
L=(SqList *) malloc (sizeof (SqList));
L - & gt; Length=0;
}
Void DestroyList (SqList * & amp; L)
{
free(L);
}
Bool ListEmpty (SqList * L)
{
Return (L - & gt; Length==0);
}
Int ListLength (SqList * L)
{
Return (L - & gt; Length);
}
Void DispList (SqList * L)
{
for(int i=0; iPrintf (" % c ", L - & gt; Data [I]);
printf("\n");
}
Bool GetElem (SqList * L, int I ElemType & amp; E)
{
If (i<1 | | i> L - & gt; Length)
return false;
E=L - & gt; Data [I - 1);
return true;
}
Int LocateElem (SqList * L, ElemType e)
{
Int I=0;
while(ii++;
If (i>=L - & gt; Length)
return 0;
The else
Return the I + 1;
}
Bool ListInsert (SqList * & amp; L, int I ElemType e)
{
int j;
If (i<1 | | i> L - & gt; Length + 1)
return false;
i--;
For (j=L - & gt; Length; J> 1; J -)
L - & gt; Data [I]=L - & gt; Data [1];
L - & gt; Data [I]=e;
L - & gt; Length++;
return true;
}
Bool ListDelete (SqList * & amp; L, int I ElemType & amp; E)
{
int j;
If (i<1 | | i> L - & gt; Length)
return false;
i--;
E=L - & gt; Data [I];
For (j=I; L - & gt; Length - 1. J++)
L - & gt; Data [j]=L - & gt; Data [j + 1);
L - & gt; Length -;
return true;
}


People know what is going on, and how to solve

CodePudding user response:

Where is your function call, the main function in where?

CodePudding user response:

 # include "sqlist. CPP 
"Int main ()
{
SqList *L;
ElemType e;
Printf (" order form basic operation is as follows: \ n ");
Printf (" (1) the initialization sequence table L \ n ");
InitList(L);
Printf (" (2), in turn, insert a, b, c, d, e element \ n ");
ListInsert (L, 1, 'a');
ListInsert (L, 2, "b");
ListInsert (L, 3, "c");
ListInsert (L, 4, 'd');
ListInsert (L, 5, 'e');
Printf (" (3) the output sequence table L: "); DispList(L);
Printf (" (4) the sequence table L length: % d \ n ", ListLength (L));
Printf (" (5) the order table L for % s \ n ", (ListEmpty (L)?" Empty ":" not null "));
GetElem (L, 3, e);
Printf (" the third element (6) sequence table L: % c \ n ", e);
Printf (" the position of the element (7) a: % d \ n ", LocateElem (L, 'a'));
Printf (" (8) in the fourth element position insert element f \ n ");
ListInsert (L, 4, 'f');
Printf (" (9) the output sequence table L: "); DispList(L);
Printf (" the third element (10) delete L \ n ");
ListDelete (L, 3, e);
Printf (" (11) the output sequence table L: "); DispList(L);
Printf (" (12) to release order table L \ n ");
DestroyList(L);
return 1;
}

CodePudding user response:

 bool ListDelete (SqList * & amp; L, int I ElemType & amp; E) 
{
int j;
If (i<1 | | i> L - & gt; Length)
return false;
i--;
E=L - & gt; Data [I];
//for (j=I; L - & gt; Length - 1. J++) {
For (j=I; J & lt; L - & gt; Length - 1. J++) {
L - & gt; Data [j]=L - & gt; Data [j + 1);
}
L - & gt; Length -;
return true;
}

For your reference ~
Look for their own problems ~
An array access, period of mistakes ~ don't care

CodePudding user response:

reference 3 building self-confidence boy reply:
 bool ListDelete (SqList * & amp; L, int I ElemType & amp; E) 
{
int j;
If (i<1 | | i> L - & gt; Length)
return false;
i--;
E=L - & gt; Data [I];
//for (j=I; L - & gt; Length - 1. J++) {
For (j=I; J & lt; L - & gt; Length - 1. J++) {
L - & gt; Data [j]=L - & gt; Data [j + 1);
}
L - & gt; Length -;
return true;
}

For your reference ~
Look for their own problems ~
An array access, period of mistakes ~ not carefully
modified or error

CodePudding user response:

reference 3 building self-confidence boy reply:
 bool ListDelete (SqList * & amp; L, int I ElemType & amp; E) 
{
int j;
If (i<1 | | i> L - & gt; Length)
return false;
i--;
E=L - & gt; Data [I];
//for (j=I; L - & gt; Length - 1. J++) {
For (j=I; J & lt; L - & gt; Length - 1. J++) {
L - & gt; Data [j]=L - & gt; Data [j + 1);
}
L - & gt; Length -;
return true;
}

For your reference ~
Look for their own problems ~
An array access, period of mistakes ~ not carefully
who know how to solve?
  • Related