Home > Back-end >  The small white data structure for help
The small white data structure for help

Time:03-26

, every brother please help, some directions the younger brother, thank you (code should be a play is not complete, I put in comments) is now the function file
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Add or delete the function of the realization of the sequence table implementation file
Update on April 13, 2020,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

# include & lt; stdio.h>
# include & lt; stdlib.h>
# include "Seqlist. H"

Void SL_Initiate (SqList & amp; L)
//order form of initialization, the structure of an empty sequence table
{
L.e lem=(ElemType *) malloc (sizeof (ElemType) * MAXSIZE);
L.l ength=0;
}

Void SL_Free (SqList & amp; L)
//release order table
{
Free (L.e lem);
}

Bool SL_IsEmpty SqList (L)
//to determine whether a sequence table empty
{
Return L.l ength==0;
}

Bool SL_IsFull SqList (L)
//determine whether sequence table full
{
Return L.l ength==MAXSIZE;
}

Void SL_Create (SqList & amp; L, int n)
//n input data element, to create a sequence table L
{
int i;
L.l ength=n;
for(i=0; iThe scanf (" % d ", & amp; L.e lem [I]);
}

Void SL_Print SqList (L)
//output the entire sequence table
{
If (L.l ength==0)
{
Printf (" The slist is empty. \ n ");
The return;
}

for (int i=0; iPrintf (" % d ", L.e lem [I]);
printf("\n");
}

Void SL_InsAt (SqList & amp; L, int I ElemType e)
//in the first place I insert a new sequence table element e, namely the element L.e lem before [I - 1] insert
The effective range of//I (1, L.l ength + 1]
{
//please add code here, complete level task
/* * * * * * * * * * the Begin * * * * * * * * */
SqList * a;
A=& amp; L;
Int j, k=99;

For (j=MAXSIZE; J> I - 1; J -)
{
A - & gt; Elem [j]=a - & gt; Elem [k].
K -;
}
A - & gt; Elem [k + 1)=e;


/* * * * * * * * * * End * * * * * * * * * */
}

Void SL_DelAt (SqList & amp; L, int I)
//delete order table L of the ith element
The effective range of//I (1, L.l ength]
{
//please add code here, complete level task
/* * * * * * * * * * the Begin * * * * * * * * */
SqList * a;
A=& amp; L;
Int k=I, j;
For (j=I - 1; j<99; J++)
{
A - & gt; Elem [j]=a - & gt; Elem [k].
K++;
}

/* * * * * * * * * * End * * * * * * * * * */
}

Void SL_DelValue (SqList & amp; L, ElemType x)
//remove the first value of the elements of x
{
//please add code here, complete level task
/* * * * * * * * * * the Begin * * * * * * * * */
SqList * a=& amp; L;

Int I, j;
for(i=0; i{
If (a - & gt; Elem [I]==x)
{
For (j=I; j<99; J++)
A - & gt; Elem [j]=a - & gt; Elem [j + 1);
The return;
}
}

/* * * * * * * * * * End * * * * * * * * * */
}

CodePudding user response:

The main function

# include & lt; stdio.h>
# include & lt; stdlib.h>
# include "Seqlist. H"
//# include "Seqlist. CPP
"
Int main ()
{
SqList L; Int n, I, x;

SL_Initiate (L);

The scanf (" % d ", & amp; N);//the number of input element
SL_Create (m, n);

The scanf (" % d % d ", & amp; I, & amp; X);//input with the position of the insert and with value of the inserted element
SL_InsAt (L, I, x);

The scanf (" % d ", & amp; I);//the location of the input element is to be deleted
SL_DelAt (L, I);

The scanf (" % d ", & amp; X);//input element's value is to be deleted
SL_DelValue (L, x);

SL_Print (L);
SL_Free (L);
}

CodePudding user response:

The header file
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The realization of the sequence table header file
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

100//# define MAXSIZE maximum length
typedef int ElemType;
Typedef struct {
ElemType * elem;//points to the starting address of the data element
Int length;//the current length of linear table
} SqList;

//declaration of functions provides:

//order form of initialization, the structure of an empty sequence table
Void SL_Initiate (SqList & amp; L);

//release order table
Void SL_Free (SqList & amp; L);

//to determine whether a sequence table empty
Bool SL_IsEmpty SqList (L);

//determine whether sequence table full
Bool SL_IsFull SqList (L);

//n input data element, to create a sequence table L
Void SL_Create (SqList & amp; L, int n);

//output the entire sequence table
Void SL_Print SqList (L);

//acquisition order form of the ith element is assigned to e, L I the effective range of [1, L.l ength],
Void SL_GetAt (SqList L, int I ElemType & amp; E);

//in order to find the first value in table L as an element of an x
//find it returns the position of the element in the table, otherwise it returns 0,
ElemType int SL_FindValue (SqList L, x);

//in the first place I insert a new sequence table element e, namely the element L.e lem before [I - 1] insert
The effective range of//I (1, L.l ength + 1]
Void SL_InsAt (SqList & amp; L, int I ElemType e);

//delete order table L of the ith element
The effective range of//I (1, L - & gt; length]
Void SL_DelAt (SqList & amp; L, int I);

//remove the first value of the elements of x
Void SL_DelValue (SqList & amp; L, ElemType x);


CodePudding user response:

Why the younger brother to run the program after program will last more than a 0 when I enter the string of data it is more a 0
5 6 to 9 11 31 9 2 10 July 9, 88
  • Related