您的位置:首页 > 其它

remove all the same elements

2015-08-21 14:26 309 查看
[code]int remove(type x)
{
    int size = currentsize;    //currentsize 为序列中元素个数
    for(int i = 0; i < currentsize; )
    {
        if(elements[i] == x)
            {
                for(int j = i; j < currentsize; j++)
                    elements[j] = elements[j + 1]; //将i后的元素前移一位
                currentsize--;  
                continue;    //删除i后所有与x相等的元素
            }
        i++;
    }
    if(size == currentsize)
    {
        cout << "can't find the element you want to remove!" << endl;
        return 0;
    }
    return 1;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: