I am trying to to Develop a Dictionary in C and it is completed almost . I want to create a List box (Auto Complete) Function . I created the List box as same as the image . And loaded the array into it . Initially the list is A-Z order and when user press ' b' , i want to display the items starting with ' b ' in the list box . Any idea ... please help me...

[img]http://www.freeimagehosting.net/uploads/a8b54f5601.jpg[/img]

Your url takes us to Free Image Hosting, but not to your picture/image. :(

You have a large sorted list, and a binary search would be excellent. You'll need a few little tweaks to it:

1) If the person types a 'b', you change that to 'b ', (b + space), so your display to the user, will be from the very top of the alphabetical order of b's, not somewhere down in the middle or near the end.

2) Since it's unlikely that your dictionary actually has a word "baaa", then you want the binary search to give you (display for you), the closest 10 or 20 words, which are immediately after "baaa".

The above is a bit more work than a normal "start at the first word and go right through the list until you reach the b's", but it is elegant, and incredibly fast.

Having said the above, I have to add that I did a database where the search began always in the middle of the database, and then just moved up or down through the records, according to the values it found, compared to the value of the "target" letter or word. On today's computers, I found this approach to be very acceptable when the database had just 3,000 records in total.

For more than 10,000 words in your dictionary, I'd use the altered binary search - especially if access to the records is over a network and it's not really fast.

Otherwise, the "start in the middle and move up or down until you find it", is OK.

So:

1) Get user's input - this is your target
2) Start in the middle of your array - don't use linked lists, they take too long. If your static array is not big enough for all your words, then "page" it, in and out of your large static array.

3) While (target < word_array[i--]);
or
if target > middle of your array word:

While (target > word_array[i++];

What helps make this so fast, is that the inner loop of the while, is just the test condition, itself, with one increment

In C you do string (multiple characters with an '\0' on the end of them) with strcmp(), of course, and you have to include <string.h>, so it's not as simple as the above pseudo-code looks.

I forgot to mention the "auto complete" function.

To simplify matters, I would always have the first letter search, stop at the first alphabetical letter match, it finds, as mentioned in my post above this one.

Then, as each letter is keyed in, the new letter is appended to the target, and the index for the search just continues to increment word by word through the dictionary, until it finds a string that matches the (now one letter longer), target string.

Does that make sense to you?

image of ListBox created

[img]http://www.freeimagehosting.net/uploads/caab9c0bd6.jpg[/img]

I am trying to to Develop a Dictionary in C and it is completed almost . I want to create a List box (Auto Complete) Function . I created the List box as same as the image . And loaded the array into it . Initially the list is A-Z order and when user press ' b' , i want to display the items starting with ' b ' in the list box . Any idea ... please help me...

[img]http://www.freeimagehosting.net/uploads/a8b54f5601.jpg[/img]

Why am I not able to see it? Should I register?

Well, Why go all that trouble. Doesn't Dani web allow us attach pictures or any file we want with a max of 10 MB, if my memory doesn't fail me.

This article has been dead for over six months. Start a new discussion instead.