473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

implement set of numbers in ansi c

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
Nov 14 '05 #1
3 2106
On 14 Apr 2004 02:28:49 -0700, ke*****@clalcredit.co.il (Keren Yehezkel)
wrote:
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

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Nov 14 '05 #2
Keren Yehezkel wrote:

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
Nov 14 '05 #3

"Keren Yehezkel" <ke*****@clalcredit.co.il> wrote in message
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.
Nov 14 '05 #4

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

Similar topics

6
by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a...
7
by: | last post by:
Borland dumped all its "Borand C++ Builder" (BCB) customers. So it is our term to dump Borland (not only BCB). As a part of my attempt to dump long-loved BCB I'm trying to investigate how one can ...
3
by: Keren Yehezkel | last post by:
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...
7
by: Abhishek Jha | last post by:
How can we write a shortest program in c to convert given number to words format. example input 5012 Output: five thousand tewlve.
45
by: bobalong | last post by:
Hi I'm have some problem understanding how JS numbers are represented internally. Take this code for an example of weirdness: var biggest = Number.MAX_VALUE; var smaller = Number.MAX_VALUE...
19
by: UG | last post by:
I just wanted to know whether any timer facility exists in C, as it is not mentioned in K&R 2, or in the ISO Draft. By timer function i mean that when we use standard input function like scanf() or...
30
by: Amar Kumar Dubedy | last post by:
How to find the greatest of three numbers without using any comparison operator or ternary operator??
14
by: thehobbit | last post by:
Hi, Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and pass the result back to a calling program in COBOL? We were able to add up to 15 digit numbers without any problems,...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
8
by: andrew.smith.cpp | last post by:
Hello how Can i get this kind of output? 1,2,3,5,8,13,21 i try it with loop but could print it. Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.