int getFirstIndexInLex(char arr[],int size)
{
    int minindex=0,i;
    for(i=1;i<size;i++)
    {
        if(arr[i] < arr[minindex])
            minindex=i;
        else if(arr[i]==arr[minindex])
            minindex=checkmin(arr,size,minindex,i);
    }
    return minindex;
}

int checkmin(char arr[],int size,int i,int j)
{
    int k=0;
    while(arr[i]!=arr[j] && k<size)
    {
        i=(i+1)%size;
        j=(j+1)%size;
        k++;
    }
    if(k==0)
        return i;                           //Strings at i and j are
both same. You can return either index
    else if(arr[i]<arr[j])                //String starting at index i
is less than string starting at index j
        return i;
    else                                    //String starting at index
j is less than string starting at index i
        return j;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to