# include
#include
Using namespace STD.
# define Max 50
# define Elemtype int
Struct List {int length; Elemtype * data (Max); The List () {length=0; }; };
Int Insert_list (List & amp; L, Elemtype & amp; A);//insert the elements of a pointer to the linear table
Int Cout_list (List& L);//will L the elements in the output
Int Delete_list_x (List& L, Elemtype & amp; X);//delete in the L value of the elements of x
Int Insert_list (List & amp; L, Elemtype & amp; A)
{
L.d ata [L.l ength]=& amp; a;
L.l ength++;
return 0;
};
Int Cout_list (List& L)
{
for(int i=0; Ireturn 0;
};
Int Delete_list_x (List& L, Elemtype& X)
{
Int k=0;
for(int i=0; I{if (* L.d ata [I]!=x)
* L.d ata [k++]=* L.d ata [I];
}
L.l ength=k;
return 0;
};
Int main ()
{
The List A;
Int a [10]=,2,3,8,4,2,7,9,5,12 {1};
for(int i=0; I<10; I++)
Insert_list (A, A, [I]).
Cout_list (A);
Int b=2;//the problem to the
Delete_list_x (A, b);//b into a [1]
CoutCout_list (A);
Int ao=0; While (1) {cout<& lt;" * * * * * * * * * * * * "& lt;Ao. If (ao) return 0; };//don't let this force flash back
}
Have comments Delete the line of your main results after changing a [1] is not right,
As shown in figure
Change before https://img.codepudding.com/202009/117273290146212.png
After https://img.codepudding.com/202009/117273290146211.png
CodePudding user response:
this is change after the resultsthis is in before the results
How can like this
CodePudding user response:
Incoming Insert_list () of the second parameter b=2: with a [1]=2 if there is no substantial differenceCodePudding user response:
References and Pointers ~... You Delete_list_x is actually the element move forward, also can become the original a [0] -- -- -- -- -- & gt; Point to the present a [1], a [1] -- -- -- -- -- & gt; A [2], and you this is so, after removed the 2, a [1] -- -- -- -- -- & gt; A [2], because you are refer to the incoming, lead to actual incoming array a [1] also became a [2]==3, so the result is certainly not correct reference pointer is good, but also with good what to say ~ ~ ~ ~ otherwise is all sorts of pit, then ~ ~ ~ ~ ~ ~ ~