Home > Back-end >  To determine the linear table to full why need maxsize - 1
To determine the linear table to full why need maxsize - 1

Time:09-28

Ah why maxsize need - 1
Turn to for help directly is greater than or equal to the maxsize is not enough, please

CodePudding user response:

Starting from 0

CodePudding user response:

Because L - & gt; Length is to be an array of the table below, if the maxsize are listed in the table below, then an array ~

CodePudding user response:

Int a [3], is actually a [0], a [1], a [2]

CodePudding user response:

Starting from 0, linear table is finally a subscript maxsize - 1, when is equal to that has been filled, than not to mention the

CodePudding user response:

The
reference 3 floor yiyefangzhou24 response:
int a [3], is actually a [0], a [1], a [2]
but the length is 3

CodePudding user response:

reference 4 floor bug10086 response:
starting from 0, linear table is finally a subscript maxsize - 1, said it had filled, when is greater than to mention the
it here not subscript maxsize - 1, is the number, maxsize representative figure is not equal to the length

CodePudding user response:

The
reference 1/f, the truth is more important than right or wrong response:
start from 0
maxsize=array length=length will be?

CodePudding user response:

refer to 6th floor xiaojiaxi_ response:
Quote: refer to 4th floor bug10086 response:
starting from 0, linear table is finally a subscript maxsize - 1, said it had filled, when is greater than to mention the
it not subscript maxsize - 1 ah, here is the number of maxsize represent the number is not equal to the length of it

See you under that code
For (k=L - & gt; length; K>=I; I -)
L - & gt; Elem [k + 1)=L - & gt; Elem [k]
If L - & gt; Length==maxsize - 1;

L - & gt; Elem [maxsize - 1 + 1)=L - & gt; Elem [maxsize - 1);
Is
L - & gt; Elem [maxsize]=L - & gt; Elem [maxsize - 1);
And because elem is supposed to be a array, length of maxsize, subscript maximum maxsize - 1; So the above statement is more than the length of the elem, crossing the line

CodePudding user response:

refer to the eighth floor truth is right or wrong response:
Quote: refer to the sixth floor xiaojiaxi_ response:

Quote: refer to 4th floor bug10086 response:
starting from 0, linear table is finally a subscript maxsize - 1, said it had filled, when is greater than to mention the
it not subscript maxsize - 1 ah, here is the number of maxsize represent the number is not equal to the length of it

See you under that code
For (k=L - & gt; length; K>=I; I -)
L - & gt; Elem [k + 1)=L - & gt; Elem [k]
If L - & gt; Length==maxsize - 1;

L - & gt; Elem [maxsize - 1 + 1)=L - & gt; Elem [maxsize - 1);
Is
L - & gt; Elem [maxsize]=L - & gt; Elem [maxsize - 1);
And because elem is supposed to be a array, length of maxsize, subscript maximum maxsize - 1; So the above statement is more than the length of the elem, crossed the
elem is indeed an array elem [maxsize], if the maxsize take 3, take the length maxsize - 1 or 2, the sequence table is not full, still can be inserted

CodePudding user response:

I think I've said is quite clear, because I didn't see all of your code, I guess so length should represent the subscript,,
Otherwise, if allow length is equal to 2
L - & gt; Elem [2 + 1]=L - & gt; Elem [2],,,,

CodePudding user response:

references to the tenth floor truth is right or wrong response:
I think I've said is quite clear, because I didn't see you of all the code, I guess so length should represent the subscript,,
Otherwise, if allow length is equal to 2
L - & gt; Elem [2 + 1]=L - & gt; Elem [2],,,,
this is
the definition of a front# define Elem type int.
Typedef struct
{
Elem type lelm [maxsize];
Int length;
}seqlist;

CodePudding user response:

Length is to require greater than or equal to maxsize - 1, or greater than or equal to the maxsize, difference is not big, but is behind the code plus one, the problem of minus one,
Do you have see other code,

CodePudding user response:

refer to 12th floor truth is right or wrong response:
length is to require greater than or equal to maxsize - 1, or greater than or equal to the maxsize, the difference is not big, but is behind the code plus one, the problem of minus one,
Specific and you see other code,
that is to say, don't - 1 can be?

CodePudding user response:

"No 1 can also be" what do you mean?????
I can't understand what are you talking about? If you don't understand, the post code, I can tell you,
  • Related