473,499 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing duplicate entries in a list.

Hi,
I have a list of integers. At each iteration, I remove some element
from it and then insert new elements in it. The order of elements is
not important. So I guess I could use a vector also for this purpose.
However, I am also interested in having no duplicacy in elements of
the vector. So I do not want to have any integer repeated more than
once in the list.
One very naive approach could be to compare the new integer being
added to every element of the list already present. Can I do any
better, by using sort() and unique() methods(in conjunction) in the
list? I am not aware of any such methods for a vector.. Any suggestions
which one might be better in terms of efficiency?

thanks,
--a.

Sep 4 '05 #1
3 2707
Uzytkownik "Amit" <am*********@gmail.com> napisal w wiadomosci
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,
I have a list of integers. At each iteration, I remove some element
from it and then insert new elements in it. The order of elements is
not important. So I guess I could use a vector also for this
purpose.
However, I am also interested in having no duplicacy in elements of
the vector. So I do not want to have any integer repeated more than
once in the list.
One very naive approach could be to compare the new integer being
added to every element of the list already present. Can I do any
better, by using sort() and unique() methods(in conjunction) in the
list? I am not aware of any such methods for a vector.. Any
suggestions
which one might be better in terms of efficiency?

If the range of integers in question is limited and you want really
efficient 'sort' and 'unique' functions, you might be better off using
a bitfield with number of fields equal to the biggest integer you wish
to store. It takes quite a lot of memory (max. range of integers / 8
bytes) but gives you zero time 'sort' and zero time 'unique' functions
:)

regards,
Filip Dreger
Sep 5 '05 #2
"Amit" <am*********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,
I have a list of integers. At each iteration, I remove some element
from it and then insert new elements in it. The order of elements is
not important. So I guess I could use a vector also for this purpose.
However, I am also interested in having no duplicacy in elements of
the vector. So I do not want to have any integer repeated more than
once in the list.
One very naive approach could be to compare the new integer being
added to every element of the list already present. Can I do any
better, by using sort() and unique() methods(in conjunction) in the
list? I am not aware of any such methods for a vector.. Any suggestions
which one might be better in terms of efficiency?

thanks,
--a.


Have a look at std::set<int>.

--
Cy
http://home.rochester.rr.com/cyhome/
Sep 5 '05 #3
In message <11*********************@z14g2000cwz.googlegroups. com>, Amit
<am*********@gmail.com> writes
Hi,
I have a list of integers. At each iteration, I remove some element
from it and then insert new elements in it. The order of elements is
not important. So I guess I could use a vector also for this purpose.
However, I am also interested in having no duplicacy in elements of
the vector. So I do not want to have any integer repeated more than
once in the list.
One very naive approach could be to compare the new integer being
added to every element of the list already present. Can I do any
better, by using sort() and unique() methods(in conjunction) in the
list? I am not aware of any such methods for a vector..
That doesn't mean you can't do it: the reason there are no
vector-specific member functions for this is merely that the generic
(non-member) std:: algorithms will work on std::vector (unlike
std::list), so there's no point in having class-specific equivalents.
Any suggestions
which one might be better in terms of efficiency?


Since you're adding and removing all the time (which would entail
repeatedly re-sorting a vector) you might do better to use std::set,
which is intrinsically sorted already.

--
Richard Herring
Sep 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
13995
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
3
6906
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER JOIN table AS t2 ON t1.field = t2.field WHERE...
3
17930
by: Rad | last post by:
I have a table . It has a nullable column called AccountNumber, which is of varchar type. The AccountNumber is alpha-numeric. I want to take data from this table and process it for my application....
4
4364
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
10
6749
by: Backwards | last post by:
Hello all, I'll start by explaining what my app does so not to confuss you when i ask my question. ☺ I have a VB.Net 2.0 app that starts a process (process.start ...) and passes a prameter...
1
3457
by: gaikokujinkyofusho | last post by:
Hi, I have been enjoying being able to subscribe to RSS (http://kinja.com/user/thedigestibleaggie) for awhile and have come up with a fairly nice list of feeds but I have run into an annoying...
2
45847
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
12
20770
by: joestevens232 | last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of which may repeat) as input into an array. Write...
7
2798
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.