lexicographic

sort with lexicographic order

I see the results from the following code, but I don't understand exactly how the or knows what to do in the following sort example: use Data::Dumper; $animals{'man'}{'name'} = 'paul'; $animals{'man'}{'legs'} = 2; $animals{'cheeta'}{'name'} = 'mike'; $animals{'cheeta'}{'legs'} = 3; $animals{'zebra'}{'name'} = 'steve'; $animals{'zebra...

String encoding of primitive types preserving lexicographic order

Does anyone know of a library for encoding a number of primitive types (like integers, floats, strings, etc) into a string but preserving the lexicographical order of the types? Ideally, I'm looking for a C++ library, but other languages are fine too. Also, one can assume that the format does not need to be encoded in the string itself ...

C++ What using for lexicographical_compare?

I wan to user the function lexicographical_compare in algorithms library in c++. But I do not know what to write as far as the using statement. For example using std::lexicographical_compare ?? How can I figure this out for my self in the future? Thanks ...

What's the simplest way of defining lexicographic comparison for elements of a class?

If I have a class that I want to be able to sort (ie support a less-than concept), and it has several data items such that I need to do lexicographic ordering then I need something like this: struct MyData { string surname; string forename; bool operator<(const MyData& other) const { return surname < other.surname || (surnam...

How do I sort an ArrayList lexicographically?

I am trying to sort an ArrayList of Strings that represent card values. So, some cards contain letters ("King") and some contain Strings containing only a number ("7"). I know to use Collections.sort, but it only sorts Strings that contain letters. How do I get the ArrayList to be sorted by number as well as alphabetically? Edit: Sorry,...

strcmp() but with 0-9 AFTER A-Z? (C/C++)

For reasons I completely disagree with but "The Powers (of Anti-Usability) That Be" continue to decree despite my objections, I have a sorting routine which does basic strcmp() compares to sort by its name. It works great; it's hard to get that one wrong. However, at the 11th hour, it's been decided that entries which begin with a number...

awk / gawk asorti() problem

Hello stack. I've got following problem with gawk's asorti function: gawk 'BEGIN{ \ a[1]=6; \ a[2]=7; \ a[3]=8; \ a[21]=9; \ a[123]=10; \ t=asorti(a, o); \ for (i=1; i<=t; i++) { \ print i,o[i]; \ } \ }' The result is: 1 1 2 123 3 2 4 21 5 3 So it's pretty clear awk, sorted indices in lexicographi...

How do I sort a collection of Lists in lexicographic order in Scala?

If A has the Ordered[A] trait, I'd like to be able to have code that works like this val collection: List[List[A]] = ... // construct a list of lists of As val sorted = collection sort { _ < _ } and get something where the lists have been sorted in lexicographic order. Of course, just because A has the trait Ordered[A] doesn't mean th...