Re: [Dev-C++] Lookup tables, with bsearch, lsearch, qsort etc.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-01-15 16:48:33
|
Lookup tables are used when the lookup parameter is non-numeric or
non-sequential.
In your case, it would be easier with a normal vector and direct indexing
after checking that PaperSize is within valid range.
If your problem had been the reverse, i.e.
height = paperformats["A4"];
a lookup table would have been a possible method to implement the
associative array, with bsearch() to locate the array entry if the array
is sorted, or lsearch() if the array is unsorted.
/Per W
On Wed, 15 Jan 2003, Daniel Glenfield wrote:
>
> I'm trying to understand lookup tables and the bsearch, lsearch, qsort
> functions. I'm trying to create a structure with an integer and a text
> string, and I want to look up the number and get the text associated with
> it. for example, at the moment I have
>
> // BIG switch here
> switch (PaperSize) // can be 1 - 41
> {
> case 1: ListBox = "Paper Type: Letter";
> Listbox->AddString(ListBoxChoice);
> break;
>
> case 2: //... the same again
> //...
> case 41: // same again
>
>
> I'm trying to replace this with a lookup table but I'm finding it difficult
> - examples on the net about bsearch are not quite what I need.
>
>
>
>
> _________________________________________________________________
> Add photos to your e-mail with MSN 8. Get 2 months FREE*.
> http://join.msn.com/?page=features/featuredemail
>
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by: Take your first step towards giving
> your online business a competitive advantage. Test-drive a Thawte SSL
> certificate - our easy online guide will show you how. Click here to get
> started: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0027en
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|