Home > Back-end >  Kneel to beg
Kneel to beg

Time:03-23

2. Read the following code, for each statement, please add comments and suggests the action of the statement and analysis of the features of the algorithm and the working process of the template & lt; Typename T> Bool SqListClass : : ListDelete (int I) {int j; If (i<1 | | i> Length), return false. For (j=I - 1; j3. Read the following code for each statement, please add comments and suggests the action of the statement and analysis of the features of the algorithm and the working process of the void Insert (SqList * & amp; L, ElemType x) {int I=0, j; While (i=I; J) L - & gt; Data [j + 1)=L - & gt; Data [j]; L - & gt; Data [j]=L - & gt; Data [j + 1); L - & gt; length++; }

CodePudding user response:

Completion modify the code in the part of the statement, for reference:
 template & lt; Typename T> Bool SqListClass : : ListDelete (int I)//class template function to delete the I position of the element 
{
Int j;
If (i<1 | | i> Length)//if I is not within the scope of returns false, not to the back of the operation,
return false;
For (j=I - 1; jData [j]=data [j + 1);//cover the previous element
Length -;//marking minus one
return true;//return success
}

Void Insert (SqList * & amp; L, ElemType x)//insert function
{
Int I=0, j;
While (iFor (j=L - & gt; Length - 1. J>=I; J -)//L started the last element in the ward a
L - & gt; Data [j + 1)=L - & gt; Data [j];//to the location of the I stop
L - & gt; Data [j]=x;//L - & gt; Data [j]=L - & gt; Data [j + 1);//insert
L - & gt; length++;//L marking gal.
}

CodePudding user response:

Even have a function, a remove elements, an insert element; Remove elements is covering strategy, that is, to find in the first position, covered at the back of the front cover, in order to complete;

Element of insert, and delete, or move backward one element, first determines whether the length range, if it is, no assignment from behind, to move backward position of an element, until to the position of the insertion, finally going to insert elements into the insert position;
  • Related