Home > Back-end >  Data structure: a table set with two order, where is the code?
Data structure: a table set with two order, where is the code?

Time:01-19

# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; String. H>

# define the SIZE of 100

Typedef int ElementType
Typedef struct
{
ElementType * array;//storage element of the array
int length;//the current length
Int capacity;//array capacity
}SqList;

//table in order to create
SqList * createList (int capacity)
{
L=(SqList *) malloc (sizeof (SqList));
L - & gt; Length=0;
L - & gt; Capacity=SIZE;
L - & gt; Array=(ElementType *) malloc (SIZE * sizeof (ElementType));

Return the L;
}

//get the order table element
Int GetElement (SqList * L, int I ElementType * e)
{
If (i<1 | | i> L - & gt; Length) {
return 0;
}
* e=L - & gt; Array [I - 1);
return 1;
}

//order table lookup
Int the find (SqList * L, ElementType e)
{
I=L - & gt; Length - 1.
While (i>=0 & amp; & L - & gt; Array [I]! E)={
i--;
}
return i;
}

//order table insert
Int insertlist (SqList * L, int I ElementType e)
{
If (L - & gt; Length>=L - & gt; Capacity)//1. Judge whether the storage space of the sequence table full
{
return 0;
}
If (i<1 | | i> L - & gt; Length + 1)/2. Whether I insert position legal
{
return 0;
}
For (k=L - & gt; Length - 1. K>=I - 1; K -)
{
L - & gt; Array [k + 1)=L - & gt; Array [k].//3. Since the last element backward
}
L - & gt; Array [I - 1]=e;//4. In the case of a position I insert element
L - & gt; length++;//5. The length of the table 1

return 1;
}

//order table delete
Int deletelist (SqList * L, int I ElementType * e)
{
If (i<1 | | i> L - & gt; Length)//1. Whether I delete position legal
{
return 0;
}
* e=L - & gt; Array [I - 1);//delete the ith element
For (k=I; K{
L - & gt; Array [] k - 1=L - & gt; Array [k].//2. Since the I + 1 move
}
L - & gt; Length -;
return 1;
}

//the length of the sequence table
Int listlength (SqList * L)
{
The return of L - & gt; Length;
}

//by the tail insertion method generates initial data
Void Addlist (SqList * L)
{
The int value.
Printf (" please enter the content, end - 1 \ n ");
The scanf (" % d ", & amp; Value);
While (the value!=1)
{
Insertlist (L, L - & gt; Length + 1, value);
The scanf (" % d ", & amp; Value);
}
}

//output data
Void Outputlist (SqList * L)
{
int i;
for(i=0; I{
Printf (" % d, L - & gt; Array [I]);
}
printf("\n");
}

//order table merging: set with the
Int mergelist (SqList * L1 and L2 SqList *)
{
Int L1_Len L2_Len;
int i;

L1_Len=listlength (* L1);
L2_Len=listlength (L2);

ElementType e;
for(i=1; I<=L2_Len; I++)
{
GetElement (L2, I, & amp; E);
if(! Find (* L1, e))//couldn't find the element in the table L1, will the element is inserted into the table in the L1
{
Insertlist (L1 + + L1_Len, e);
}
}

}

Int main ()
{
LA SqList * and * LB.
ElementType e;

SqList * LA=createList (capacity);
SqList * LB=createList (capacity);

Printf (" the tail insertion method to generate the initial data: \ n ");

Addlist (& amp; LA);
Printf (" LA element in the table is: ");
Outputlist (& amp; LA);

Addlist (& amp; LB);
Printf (" LB elements in the table is: ");
Outputlist (& amp; LB);

Mergelist (& amp; LA, & amp; LB);
Printf (" LA and LB and set the elements of the: ");
Outputlist (& amp; LA);

return 0;
}
This is a program error:
\ \ sequence table \ Sqlist_Operate data structure and algorithm c (9) : error C2054: expected '(' to follow' ElementType '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (13) : error C2085: 'SqList' : not in formal parameter list
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (16) : error C2061: syntax error: identifier 'SqList'
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (27) : error C2143: syntax error: missing ') 'before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (27) : error C2143: syntax error: missing '{' before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (27) : error C2059: syntax error: 'type'
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (27) : error C2059: syntax error: ')
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (37) : error C2143: syntax error: missing ') 'before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (37) : error C2143: syntax error: missing '{' before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (37) : error C2370: 'ElementType: redefinition. Company's storage class
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (7) : see declaration of 'ElementType'
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (37) : error C2146: syntax error: missing '; 'before the identifier' e '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (37) : error C2059: syntax error: ')
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (38) : error C2054: expected '(' to follow' e '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (47) : error C2143: syntax error: missing ') 'before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (47) : error C2143: syntax error: missing '{' before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (47) : error C2059: syntax error: 'type'
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (47) : error C2059: syntax error: ')
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (68) : error C2143: syntax error: missing ') 'before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (68) : error C2143: syntax error: missing '{' before' * '
F: \ \ sequence table \ Sqlist_Operate data structure and algorithm c (68) : error C2059: syntax error: 'type'
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related