Sorting a List

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Balaji. M.

    Sorting a List

    Hi All,

    Help me to sort out the contents in the list box.

    The list box contains data elements like <first name> + <middle name> +
    <last name> as "Balaji Muthu Varathan"

    I want to sort it based on user preferences.
    ie. either it can be sort by last name or middle name or first name or
    in combinations

    With regards
    Balaji. M

  • Dr John Stockton

    #2
    Re: Sorting a List

    JRS: In article <1084535456.689 127@sj-nntpcache-5>, seen in
    news:comp.lang. javascript, Balaji. M. <bmuthuva@cisco .com> posted at
    Fri, 14 May 2004 17:22:53 :
    [color=blue]
    >Help me to sort out the contents in the list box.
    >
    >The list box contains data elements like <first name> + <middle name> +
    ><last name> as "Balaji Muthu Varathan"
    >
    >I want to sort it based on user preferences.
    >ie. either it can be sort by last name or middle name or first name or
    >in combinations[/color]

    The standard answer will be to write a comparison function parameterised
    by a global variable, or a set of comparison functions chosen by a
    global variable, in order to compare two given entries.

    If the list is too long, this will waste time, because the function will
    for a N element list be called N ln N times, and will have to compute
    two keys at each call. It will be better to make a single pass through
    the list replacing each element by an object {key, element} where key is
    the computed sort key for the current sort order, then to do the default
    sort, then do another pass to remove the key. A key might, for example,
    be Varathan, Balaji Muthu .

    Or so I suspect.

    The standard language references cover sort functions.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    • G Roydor

      #3
      Re: Sorting a List

      voyez les expressions rationnelles; (regular expressions) !
      GR

      Balaji. M. a écrit:[color=blue]
      > Hi All,
      >
      > Help me to sort out the contents in the list box.
      >
      > The list box contains data elements like <first name> + <middle name> +
      > <last name> as "Balaji Muthu Varathan"
      >
      > I want to sort it based on user preferences.
      > ie. either it can be sort by last name or middle name or first name or
      > in combinations
      >
      > With regards
      > Balaji. M
      >[/color]

      Comment

      Working...