Page 1 of 1

How use Upper_bound() function in a structure array

Posted: Thu Jun 09, 2011 11:14 am
by Najmuzzaman

Code: Select all

#include <stdio.h>
#include <algorithm>
using namespace std;
struct node{
    int a,b;
}arr[10];

int main()
{
    for(i=0;i<10;i++)
    {
        arr[i].a=i+10;
        arr[i].b=i+12;
    }
    int it=(int)(upper_bound(arr,arr+10,10)-arr);
    printf("the position is %d");
}
Do not work

Re: How use Upper_bound() function in a structure array

Posted: Mon Jun 13, 2011 12:42 am
by zobayer
you need to write a compare function that determines the behavior of your structre.
you can find out that from http://www.cplusplus.com