Re: sorting questing

new topic     » goto parent     » topic index » view thread      » older message » newer message

John McAdam wrote:

> I have a list of words that I want to sort
> by word length.

How about:

  include sort.e
  sequence q
  q = { "z", "foo", "bar", "ba", "grill", "za" }

  -- attach the negative length
  for i = 1 to length( q ) do
      q[i] = { -length(q[i]), q[i] }
  end for

  -- sort
  q = sort( q )

  -- display; element #2 is the text
  for i = 1 to length( q ) do
      puts( 1, q[i][2] & '\n' )
  end for

-- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu