Need some help with a bit of simple code

Eeezee

Diamond Member
Jul 23, 2005
9,922
0
76
I have 2 lists of numbers, and each of those lists is divided into two columns. These lists are quite large (> 100,000 entries) and each list has a different number of entries.

I need a program that can take the first list and compare the numbers in that list to the second list. That's my first hurdle; wtf?

Next is the comparison. I need to compare first column to first column and likewise for the second column. I need to start with a number in the first column and scan through the second list's first column looking for a duplicate to within +- 1. After this is done, I need to take the found entries and do the same procedure for the second column.

I'm lost. I'm a linux noob too, so if there are any handy programs out there that I just don't know of then that could help too.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Your problem is not OS related.

Fundimentally, what you are looking for is two sorted lists that support a search function.

Look into the STL (Standard Template Library) in the vector/list area.

Hopefully you can utilize the STL but will have to use a C++ compiler. Most C compilers will also do C++.
 

bersl2

Golden Member
Aug 2, 2004
1,617
0
0
Well, in standard ANSI C, there is a function qsort(), which will sort arrays, and a function bsearch(), which will search for a value through a sorted array. The most advanced concept you need in order to use these functions is function pointers, and the usage in this case is really easy.

True, there is the STL from C++, but you did say C, so I'm telling you the C equivalent.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: bersl2
Well, in standard ANSI C, there is a function qsort(), which will sort arrays, and a function bsearch(), which will search for a value through a sorted array. The most advanced concept you need in order to use these functions is function pointers, and the usage in this case is really easy.

True, there is the STL from C++, but you did say C, so I'm telling you the C equivalent.

Thanks - I could not remember the C library functions that would support his needs.


 

Eeezee

Diamond Member
Jul 23, 2005
9,922
0
76
qsort() and bsearch(), proof that my C knowledge is infinitely tiny

thanks a bunch