implement set of numbers in ansi c

Discussion in 'C Programming' started by Keren Yehezkel, Apr 14, 2004.

  1. 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
     
    Keren Yehezkel, Apr 14, 2004
    #1
    1. Advertising

  2. Keren Yehezkel

    Leor Zolman Guest

    On 14 Apr 2004 02:28:49 -0700, (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
     
    Leor Zolman, Apr 14, 2004
    #2
    1. Advertising

  3. Keren Yehezkel

    Default User Guest

    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
     
    Default User, Apr 14, 2004
    #3
  4. Keren Yehezkel

    Malcolm Guest

    "Keren Yehezkel" <> 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.
     
    Malcolm, Apr 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    7
    Views:
    4,686
    Kleidemos
    Aug 31, 2004
  2. Kaz

    How to set ansi.sys for windows.xp?

    Kaz, Nov 23, 2004, in forum: C Programming
    Replies:
    8
    Views:
    707
    CBFalconer
    Nov 28, 2004
  3. Replies:
    1
    Views:
    520
  4. Replies:
    11
    Views:
    1,124
    Keith Thompson
    Apr 28, 2008
  5. Frank Iannarilli

    pre-ansi to ansi c++ conversion?

    Frank Iannarilli, Jul 21, 2009, in forum: C++
    Replies:
    2
    Views:
    442
Loading...

Share This Page