删除数组中的实例 [英] deleting instance in array

查看:106
本文介绍了删除数组中的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我想知道是否可以删除数组中的实例,

以下不允许我这样做删除。

我试图找到并删除数组中的副本,谢谢

for(j = 0; j< MAX; j ++)

{

for(i = 0; i< MAX; i ++)

{

if(array_3 [i] == array_3 [ j + i])

{删除array_3 [i];

}


}

}


Dan

hello,

I would to know if it is possible to delete an instance in an array, The
following does not allow me to do a delete.
I am trying to find and delete the duplicate in an array, thanks
for ( j =0; j<MAX ; j++)
{
for ( i =0; i<MAX ; i++)
{
if (array_3[i] == array_3[j + i] )
{delete array_3[i];
}

}
}

Dan

推荐答案



" Dan" ; < Dan @ hotmail.com>在消息中写道

news:c4 **************** @ news20.bellglobal.com ...

"Dan" <Dan@ hotmail.com> wrote in message
news:c4****************@news20.bellglobal.com...
你好,

我想知道是否可以删除数组中的实例,
以下不允许我删除。
我试图找到并删除复制数组,谢谢

for(j = 0; j< MAX; j ++)
{
for(i = 0; i< MAX; i ++) {
if(array_3 [i] == array_3 [j + i])
{delete array_3 [i];
}

}
}
hello,

I would to know if it is possible to delete an instance in an array, The
following does not allow me to do a delete.
I am trying to find and delete the duplicate in an array, thanks
for ( j =0; j<MAX ; j++)
{
for ( i =0; i<MAX ; i++)
{
if (array_3[i] == array_3[j + i] )
{delete array_3[i];
}

}
}




什么不起作用?是否会崩溃?


如何创建阵列的每个成员?如果您使用类似


array_3 [i] = new someobjectyouhavenotshown;


那么你正在删除它。这假设数组包含

指针。是吗?


或者,您是否期望第i个项目消失,除此之外的所有项目都会向上移动一个空间?


你需要更具体地说明数组包含什么,如何填充
(即,它的项目是如何创建的),以及你的意思你说

它不允许你删除。


也许你想要使用的是std :: vector,而不是数组。但是没有

更多信息,这是不可能的。


-Howard



What does not work? Does it crash?

How do you create each member of the array? If you use something like

array_3[i] = new someobjectyouhavenotshown;

then you''re deleting it properly. This assumes that the array holds
pointers. Does it?

Or, are you expecting the ith item to go away, and all items beyond that to
shift up one space?

You''ll need to be more specific about what the array contains, how it is
populated (i.e., how are its items created), and what you mean when you say
it doesn''t allow you to do a delete.

Perhaps what you want to use is a std::vector, not an array. But without
more info, it''s impossible to tell.

-Howard



" Dan" < Dan @ hotmail.com>在消息中写道

news:c4 **************** @ news20.bellglobal.com ...

"Dan" <Dan@ hotmail.com> wrote in message
news:c4****************@news20.bellglobal.com...
你好,

我想知道是否可以删除数组中的实例,
以下不允许我删除。
我试图找到并删除复制数组,谢谢

for(j = 0; j< MAX; j ++)
{
for(i = 0; i< MAX; i ++) {
if(array_3 [i] == array_3 [j + i])
{delete array_3 [i];
}

}
}
hello,

I would to know if it is possible to delete an instance in an array, The
following does not allow me to do a delete.
I am trying to find and delete the duplicate in an array, thanks
for ( j =0; j<MAX ; j++)
{
for ( i =0; i<MAX ; i++)
{
if (array_3[i] == array_3[j + i] )
{delete array_3[i];
}

}
}




用C ++改变数组的大小是不可能的,所以你试图用b $ b来做一些相当困难的事情。 />

最简单的方法是学习可以调整大小的向量。

给自己一本现代的C ++书,教你向量。


john



It is impossible to change the size of an array in C++, so you are trying to
do something rather difficult.

The easiest way to do this is to learn about vectors, which can be resized.
Get yourself a modern C++ book that teaches you about vectors.

john


Dan写道:
我想知道是否可以删除一个实例一个rray,
以下不允许我删除。
我试图找到并删除数组中的副本,谢谢


你会是什么?期待结果是?说,我有一个数组

开头:


int int_array [] = {1,2,3,4,3,2};


我想删除重复的''2''。在我完成删除之后,数组应该是什么?
(j = 0; j< MAX; j ++)
对于(i = 0; i< MAX; i ++)
{
if(array_3 [i] == array_3 [j + i])
{delete array_3 [i];
}

}
}
I would to know if it is possible to delete an instance in an array, The
following does not allow me to do a delete.
I am trying to find and delete the duplicate in an array, thanks
What would you expect the result to be? Say, I have an array
to begin with:

int int_array[] = { 1, 2, 3, 4, 3, 2 };

and I want to delete the duplicate ''2''. What should the array
be after I finish "deleting" from it?


for ( j =0; j<MAX ; j++)
{
for ( i =0; i<MAX ; i++)
{
if (array_3[i] == array_3[j + i] )
{delete array_3[i];
}

}
}



这篇关于删除数组中的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆