well I'm trying to write a program that needs to sort the suffixes of an array. Let A be an array of characters:
now to sort the suffixes I would naively brake and array into 9 suffix arrays and the sort them out and get something like this:@A = (A,C,D,D,C,D,A,G,F);
ACDD... AGF CDA... CDD... DAG... .... now, how do i do this without chopping thees into sub-arrays, and just do it via references like in c, where you do this through pointers (references).thnx
baxy
UPDATE:
well thnx ppl for the quick help but there is still a problem that i was not aware of ..... so in the following code i get a strange solution:
isn't "acaaacatatz" lexicographically lower then "aacatatz" ???????(SOLVED : see the code below) Oh , I just saw your other comments , so what i'm playing arround is Kasai's algorithm so the whole code is : ---#!/usr/bin/perl use strict; my @array = qw(a c a a a c a t a t z); my @sorted = sort { $array[$a] cmp $array[$b] } (0 .. $#array); print join('',@array[$sorted[$_] .. $#array]) . "\n" for 0..10; #prints acaaacatatz aaacatatz aacatatz acatatz atatz atz caaacatatz catatz tatz tz zUPDATE2 : all corrected and below is the working code if anyone needs is, it is a bit naive but illustrates the point and it works Code was moved to : Kasai's algorithm so if someone is looking for it, well here it is , in Perl !!!!
In reply to [SOLVED]How to sort the referencese by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |