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. 3 2716
Uzytkownik "Amit" <am*********@gm ail.com> napisal w wiadomosci
news:11******** *************@z 14g2000cwz.goog legroups.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
"Amit" <am*********@gm ail.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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/
In message <11************ *********@z14g2 000cwz.googlegr oups.com>, Amit
<am*********@gm ail.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 entry you cannot choose the same value twice.
For example, I cannot choose for entry 1 the same
value in both selection boxes (gqCategory1Entry1 and
gqCategory2Entry1)
|
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 t1.id < t2.id
|
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. Before doing
that I would like to filter out duplicate AccountNumbers. I get most of
the duplicates filtered out by using this query:
select * from customers
where AccountNumber NOT IN (select AccountNumber from customers where
AccountNumber...
|
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
import cPickle
book = {raw_input("Name: "): }
file_object = file(database, 'w+')
cPickle.dump(book, file_object)
|
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 through from a combo box. The combo box items are
made up of IP address and computer host name. Anything a user places in
this combo box it writes this to a txt file called history.txt
| |
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
(though not critical) problem, duplicate stories. Apparently there is
overlap with some of the sites I subscribe to so I get duplicate
stories. Does anyone know of some sort of filter (software or online
service) that can remove duplicate stories? Any...
|
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 and the corresponding model numbers (primary key on serial_numbers)
Since Table A has no constraints duplicates may exist.
Additionally, table A is actually an Excel spreadsheet that is maintained by an employee that records new hardware as...
|
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 a function that processes the array so that any duplicate values are eliminated. Write
an output function that prints out the values of the array. You can assume that there are no more than 20
integers in the input. But there may be less. Zero...
|
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 to support cloning:
Public Class RefClass
Public tcp As TcpClient
Public name As String
End Class
Public Class RefClassList
Inherits List(Of RefClass)
Implements ICloneable
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |