insert in order

This is a discussion on insert in order within the C Programming forums, part of the General Programming Boards category; my program should declare a 2D array of char in main.this array hold all the strings that are read in ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Question insert in order

    my program should declare a 2D array of char in main.this array hold all the strings that are read in from an input file that is specified on the command lin. after dimensioning the dicionary array, I must pass it to a loadDictionary() function that will open tha input file.read all the strings and then close th input file.my load must update a word count as we read in words from the file,keep the dictionary in sorted order at all times and the array should be sorted as it is being loaded which is insert in order.So
    the problem is that I donot know how I should insert in order?

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    Each time you insert a new entry, search through until you find a string greater alphabetically than your new entry, then move all the elements from that string to the end up one index. Then insert the new entry.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Sine your array will be sorted at all times, you can use the bsearch function to efficiently find the insertion point.

  4. #4
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    How? bsearch will return null if the entry isn't there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laplace Expansion
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 11:26 PM
  2. Embedded SQL Order By
    By cjohnman in forum C Programming
    Replies: 12
    Last Post: 04-15-2008, 03:45 PM
  3. How do you order your game code?
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 02-05-2006, 05:26 PM
  4. correct order to insert new node?
    By campermama in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2004, 07:51 PM
  5. what is the significance of low order and high order bits
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 10:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21