By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

help on implementation algorithms on vector

P: n/a
I have a implementation problem:
I writed bad code and large code.

I have a vector stl, and every element have a float and a sign.

10(+) 20(-) 20.001(-) 20.002(+) 20.003(-) 20.003(-) 50(+) 51(-)
52.001(+) 52.002(+)

I would like erase close elements of vector in this seguent way:
- if elements have discordant signs I deleted them.
- if elements have itself signs I deleted all except the first.
I use espilon < 0.01 to compare.

the result must be:

10(+) 50(+) 51(-) 52.001(+)
For example:

the first element is 20(-) and the last is 20.003(-)
20.001-20<epsilon
20.002-20<epsilon
20.003-20<epsilon
.....

I deleted all because have discordant signs

Can you show me a implementation?

Thanks.

Mar 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mar 19, 11:50 am, "antani" <antani8...@yahoo.itwrote:
I have a implementation problem:
I writed bad code and large code.

I have a vector stl, and every element have a float and a sign.

10(+) 20(-) 20.001(-) 20.002(+) 20.003(-) 20.003(-) 50(+) 51(-)
52.001(+) 52.002(+)

I would like erase close elements of vector in this seguent way:
- if elements have discordant signs I deleted them.
- if elements have itself signs I deleted all except the first.
I use espilon < 0.01 to compare.

the result must be:

10(+) 50(+) 51(-) 52.001(+)

For example:

the first element is 20(-) and the last is 20.003(-)
20.001-20<epsilon
20.002-20<epsilon
20.003-20<epsilon
....

I deleted all because have discordant signs

Can you show me a implementation?
No per <http://www.parashift.com/c++-faq-lite/how-to-
post.html#faq-5.2>, but if you have a specific language-related
question (like how to use std::remove_if), feel free to ask it.

Cheers! --M

Mar 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.