BSearch على عناصر متعددة في بنية
-
10-12-2019 - |
سؤال
ثابت.
تشمل giveacodicetagpre.
كما ترون أنني وضعت ما أعتقد أنه صحيح أن استدعاء BSearch، ولكن إذا كان من المناسب، فأنا لست متأكدا من أين أذهب من هنا.
المحلول
If you're searching for a specific date, then use a struct date
as a key:
struct date Jan;
Jan.month = 0;
Jan.year = 00;
Jan.day = 1;
Then you can use your sortDates
function (you should rename it to compareDates
):
struct date* pos = bsearch(
&Jan, /* pointer to the structure above */
list, /* pointer to your array */
n, /* number of elements in your array */
sizeof(struct date), /* size of each element */
(compfn)sortDates /* compare function */
);
See also http://www.cplusplus.com/reference/clibrary/cstdlib/bsearch/ and http://en.cppreference.com/w/cpp/algorithm/bsearch for further examples.
لا تنتمي إلى StackOverflow