implement set of numbers in ansi c

K

Keren Yehezkel

Hello every one,

I'm a new programmer in c

I would like to know what is the most efficient way
To create a set (group with no duplicate members)
From a user input (only integers), while reserving the order that
the input was received in.

If there is some similar code source,
I would appreciate it.

Thanks,

Keren
 
L

Leor Zolman

Hello every one,

I'm a new programmer in c

I would like to know what is the most efficient way
To create a set (group with no duplicate members)
From a user input (only integers), while reserving the order that
the input was received in.

If there is some similar code source,
I would appreciate it.

A typical implementation would use a binary tree. Google for this, and you
may find something useful:
"implementation for binary search tree"
You may have to tailor the code to ensure uniqueness of the values, but
that wouldn't be difficult.
-leor
 
D

Default User

Keren said:
Hello every one,

I'm a new programmer in c

I would like to know what is the most efficient way
To create a set (group with no duplicate members)
From a user input (only integers), while reserving the order that
the input was received in.


This is not really a C question, but an algorithm one. Try
comp.programming. Once you have settled on your design, then we can help
you implement it in C.




Brian Rodenborn
 
M

Malcolm

Keren Yehezkel said:
I would like to know what is the most efficient way
To create a set (group with no duplicate members)
From a user input (only integers), while reserving the order that
the input was received in.
This all depends what you mean by efficiency. There is runtime efficiency,
memory efficiency and, as a rule the most important of all, programming
efficiency.
If you have an upper bound on the size of your set then just creating an
array, walking through it to look for duplicates, and appending an
non-duplicate is probably the best way to go.
This isn't the most efficient way of doing things if the input is very
large, but on a decent machine you probably won't have to worry about this.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top