Home > Back-end >  Linear table, said code 0 error, but the runtime runs not bottom go to, please look at this kind of
Linear table, said code 0 error, but the runtime runs not bottom go to, please look at this kind of

Time:09-25

 # include 
# include
# define Maxsize 5


//int I is the length of the linear table



Typedef struct List//the definition of linear List
{
Char data [Maxsize];
int length;
} the List;

Void inList (List * L)//the initialization of the linear table
{
L=(List *) malloc (sizeof (List));//assign linear table space
L - & gt; Length=0;//to make long table 0
}

Void InputList (List * L, int I)//to linear table input element
{
Int p;
For (p=0; p{
Printf (" please input you want to input elements: ");
The scanf (" % c ", & amp; L - & gt; Data [p]);
}
}

Void outputList (List * L, int I)//output linear table element
{
Int p;
For (p=1; p{
Printf (" the first % d linear table element is: the "% c, p and L - & gt; Data [p]);
printf("\n");
}
}

Int InsertList1 (List * L, int I)//tail interpolation insert element
{
Int p, m;
Printf (" please enter the number you want to insert elements: ");
The scanf (" % d ", & amp; P);
L - & gt; Length=I + p;
For (m=1; (m + I) & lt;=L - & gt; Length; M++)
{
Printf (" please input you want to input elements: ");
The scanf (" % c ", & amp; L - & gt; Data [m + I]);
}

The return of L - & gt; Length;//returns the number now element
}

Int InsertList2 (List * L, int I)//in the middle insert element
{
int m;
Which element the printf (" what do you plan to insert the new element: ");
The scanf (" % d ", & amp; M);
for(; i>=m; I -)
{
L - & gt; Data [I + 1)=L - & gt; Data [I];//make m after the element are a behind, start from the bottom to move
}
Printf (" do you want to insert elements is: ");
The scanf (" % c ", & amp; L - & gt; Data [m]);
L - & gt; Length++;
The return of L - & gt; Length;//returns the length of the linear table now
}

Int deleteList (List * L, int I)//remove linear table element
{
int m;
Printf (" input the linear table which you want to delete elements: ");
The scanf (" % d ", & amp; M);
for(; M<=I; M++)//since deleted elements, elements of collective move forward a
{
L - & gt; Data [m]=L - & gt; Data [m + 1];
}
The return of L - & gt; Length;
}

Void DestoryList (List * L)//destruction of linear table
{
Free (L);
}

Int main ()//main function
{
Int I, a;
The List * L;

Printf (" please input you want to input the number of elements: ");//get the linear length of the table, I long for the table
The scanf (" % d ", & amp; I);

InputList (L, I);

OutputList (L, I);

I=InsertList1 (L, I);

OutputList (L, I);

Linear table the third element is: printf (" % c ", L - & gt; Data [3]);//output linear table the third element
Printf (" the length of the linear list is: % d ", I);//output linear table length

I=InsertList2 (L, I);//insert the new element, update the insert element after the length of the linear table

For (a=1; A<=I; +)//output linear table element
{
Printf (" linear table elements are: % c, L - & gt; Data [a]);
}

I=deleteList (L, I);//remove linear table

OutputList (L, I);//output is linear table element

DestoryList (L);//destroy linear table
return 0;
}


Using vc runtime to input the step input is not into the element


Using vc debugging, this

In other runtime compiler so,,,

CodePudding user response:

L in the main function pointer initialization not
InList function in the function change to L, does not affect the function pointer pointing to outside, so it should be the secondary pointer, namely the inList (List
* * L), and then call it first in the main initialization L

CodePudding user response:

reference 1st floor qybao response:
L in the main function pointer initialization not
InList function in the function change to L, does not affect the function pointer pointing to outside, so it should be the secondary pointer, namely the inList (List
* * L), and then call it first in the main initialization L

Don't understand why want to use the secondary pointer, I found that the main initialization functions do not put in
  • Related