您的位置:首页 > 其它

有序线性表指定元素的全部删除

2014-05-01 18:55 381 查看
设计一种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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐