Ps: In each piece of code, the signature solo is written by the blogger himself, and the rest comes from a textbook or teacher.
Defines the storage structure of a linear table #define MAXSIZE typedef struct {elemtype elem[maxsize];//elemtype custom int last;}
Seqlist;
Linear table by Find contents Operation Locate (l,e) function int Locate (seqlist L, elemtype e) {i = 0;
while ((I <= l.last) && (l.elem[i]! = e)) i++;
if (i <= l.last) return (i + 1);
else return (-1);
}//Linear table insert operation #define OK 1 #define ERROR 0 int inlist (seqlist *l, int i, elemtype e) {int k;
if (I < 1 | | i > l->last+2) {printf ("Insert position I is not legal");
return ERROR;
} if (L->last >= MAXSIZE-1) {printf ("The table is full and cannot be inserted");
return ERROR;
} for (k = l->last; k >= i-1; k--) l->elem[k+1] = l->elem[k];
L->elem[i-1] = e;
l->last++;
return OK;
}//The delete operation of the linear table int dellist (seqlist *l, int i, elemtype *e) {int k;
if (I < 1 | | i > l->last+1) {printf ("Delete location is not valid");
return ERROR; }
*E = l->elem[i-1];
for (k = i; I <= l->last; k++) l->elem[k-1] = elem[k];
l->last--;
return OK;
}//Linear table in-place inverse int Slistrev (seqlist *l) {int i;
Elemtype T;
for (i=0; i<l->last/2; i++) {t = A[i]; A[i] = a[n-i-1]; a[n-i-1] = t;
} return Ok;
}//Linear table merge operation 1 void Mergelist (Seqlist *la, Seqlist *lb, seqlist *lc) {int i,j,k; i=0; j=0;
k=0;
while (I <= la->last && J <= lb->last) if (La->elem[i] <= lb->elem[j]) {
Lc->elem[k] = la->elem[i]; i++;
k++;
} else{Lc->elem[k] = lb->elem[i]; j + +;
k++;
} while (I <= la->last) {Lc->elem[k] = la->elem[i]; i++;
k++;
} while (J <= Lb->last) {Lc->elem[k] = la->elem[j]; j + +;
k++;
} lc->last = la->last + lb->last + 1; }
The combined operation of the linear table 2--solo void Mergelist (Seqlist *la, Seqlist *lb, seqlist *lc) {int i,j,k; i=0; j=0;
k=0; while (i <= la->last | | J <= lb->last) if (La->elem[i] <= Lb->elem[i] | |
(I <= la->last && J > Lb->last)
{Lc->elem[k] = la->elem[i]; i++;
k++; } if (La->elem[i] > Lb->elem[j] | |
(i > La->last && J <= Lb->last))
{Lc->elem[k] = lb->elem[i]; j + +;
k++;
} */* Delete all values in non-descending order table L equal element--solo*///① If the value of equality is only one, E, only in this case can meet the requirements of the data structure textbook exercise void Delsame (Seqlist *l e) {int i,j;
for (i=0,j=0; i<l->last; i++) if (l->elem[i]! = e) {L->elem[j] = l->elem[i]; j + +;}
L->last = j+1;
}//② If the value of equality is many, and is not sure two methods void Delmulsame (Seqlist *l) {int i,j,k; For (i=0, i<l->last; i++) for (j=1; j<l->last; J + +) {if (l->elem[i] = L->el
EM[J]) for (k=j; j<l->last; k++) {L->elem[k] = l->elem[k+1];
l->last--;
}}} void Delmulsame (Seqlist *l) {int i,j,k,t; for (i=0; i<l->last-1; i++) {for (k=i, j=i+1; j<n; j--)//bubble sort if (A[j] <
A[k]) k = j;
if (k! = i) {t = A[i]; A[i] = a[k]; a[k] = t;} }/* for (i=0; i<l->last-1; i++)//This paragraph is commented out, is the selection method sort for (j=l-last-1; j>=i; j--) if (A[j] > A[j+1]) {a[j] = t; a[j] = a[j+1]; a[j+1] = A[j];}
*/for (i=0; i<l->last; i++) {if (l->elem[i] = l->elem[i+1]) {
for (k=i; k<l->last; k++) {L->elem[k] = l->elem[k+1];
k--;
l->last--;
} }
}
}
Zhihu:solo | weibo@ from basin to sea