As others have said, you have not completely specified the problem.
If you always have exactly 4 base 10 numbers separated by dots, and
you are working in C or C++ then you can use sscanf to get the numbers
and compare them:

// Return:
//  positive if version s1 is an earlier version than s2,
//  negative if s2 is earlier than s1
//  zero if they're the same version
#define VERSION_CMP_ERROR INT_MAX
int version_cmp(char *s1, char *s2)
{
  int i, v1[4], v2[4];
  if (sscanf(s1, "%u.%u.%u.%u", v1+0, v1+1, v1+2, v1+3) != 4 ||
      sscanf(s2, "%u.%u.%u.%u", v2+0, v2+1, v2+2, v2+3) != 4)
   return VERSION_CMP_ERROR;
  for (i = 0; i < 4; i++)
    if (v1[i] != v2[i])
      return v2[i] - v1[i];
  return 0;
}

On Oct 11, 4:52 am, "bagaria.ka...@gmail.com"
<bagaria.ka...@gmail.com> wrote:
> Given two strings describing the version of a particular software need to
> find the later version.
>
> For eg.
> 1st string = "1.2.4.5"
> 2nd string="1.2.3.5"
>
> 1st string is the later one.
>
> Can be done using traversing the string and comparing each character one
> after the another. Looking for a better solution with lesser complexity.
>
> --
> Thanks and Regards
>
> *Karan Bagaria*
> *MCA Final Year*
> Training and Placement Representative
> *NIT Durgapur*

-- 
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