Which data structure should I use?

J

Julia Jin

Hi, there,

I have a list of elements. Each time when a new data comes in, I need
to check if the new data exists in the list. If not exists, I need to
insert the new data into the list.

If I keep the list unsorted, when the length of the list becomes
large, it takes a long time to check if an elements exists in the list
or not.

In this case, which data structure should I use? Can anyone give me
some suggestion or a short piece of C code? Thanks!

Julia
 
E

Ema

Julia Jin said:
Hi, there,

I have a list of elements. Each time when a new data comes in, I need
to check if the new data exists in the list. If not exists, I need to
insert the new data into the list.

If I keep the list unsorted, when the length of the list becomes
large, it takes a long time to check if an elements exists in the list
or not.

In this case, which data structure should I use? Can anyone give me
some suggestion or a short piece of C code? Thanks!

It depends:
- on the type of your data
- (if your data are record (struct)) on the kind of existence check (on all
the record, on one particular field, ...)

You can try hash tables:
- as alternative data structure to lists
- as auxiliary "existence check" data structure, to use together with lists

I apoligize for my bad English... :-(

Ciao,
Ema
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top