设计一种O(n)级算法从有序线性表中删除与给定的数据项相匹配的所有数据项。假设线性表用数组表示
template <class T>
void clearAllMatchElement(T arySource[], int &iArySize, const T &valueTarget)
{
int iCountMatch = 0;
int i =0;
while (i < iArySize)
{
if (arySource[i] == valueTarget)
{
++iCountMatch;
int j = i + 1;
for (; j < iArySize; j++)
{
. if (arySource[j] != valueTarget)
{
arySource[j - iCountMartch] = arySource[j];
}
else
break;
}
i = j;
}
else
++i;
}
iArySize -= iCountMatch;
}