Re: ordinate a sequences of number




gambato@xxxxxxxxxxxx wrote:
> ....I want to organize all my numbers so that the first is the
> smallest one and the last is the bigger one.
> why do you say that I haven't yet read the elements from 2 to n?
> I thought: I read n-1 elements and I compare the first elements with
> successive one (j=2,n) and so on the second one with j=3,n, etc....
> But the problem is that the program doesn't save the ordinate numbers
> in the array pos(i).

Read all of the numbers first. Then sort them.

For a data set with over 100000 items, the performance of any sorting
routine that compares each item with every other item is going to be
dismal. Look up "comb sort". It is easy to code. It is about half as
fast as quick sort. Usually this is good enough.

Last, what do you want POS() to contain? The sorted data OR the index
of the sorted data in the un-sorted list?

For example, given data

9 3 4

should POS() contain the sorted data

3 4 9

or should it be

2 3 1

If the latter, then you need to fill POS() with the integers 1 to N
before you sort. Then you must modify your sort routine so that it
references X(POS(I)) instead of X(I).

e-mail: epc8 at juno dot com

.



Relevant Pages

  • Re: CListCtrl, hide and edit
    ... Looks like n**2 bubble sort. ... bool CDialogWithList::CompareAndSwapString1(int pos, bool bAscending) ... CMyObjectInfo *temp; ... So I don't use the sort mechanism in the list control at all. ...
    (microsoft.public.vc.mfc)
  • Re: OT: Algorithm to speed up vector range search
    ... > I hope you guys can help me solve a problem that i am having with speeding ... data according to min (and of course keep the sorted data around for the ... You can do the same in the other direction (sort according to max, ... There is even a clever technique to combine both methods into one. ...
    (comp.lang.cpp)
  • Re: Merge sort on Linked List
    ... I have to write program in C# to merge sort a linked list (doubly ... foreach (int elt in myLL) ... public static void MergeSort ... LinkedListNodemidL, pos; ...
    (microsoft.public.dotnet.languages.csharp)
  • Merge sort on Linked List
    ... I have to write program in C# to merge sort a linked list (doubly ... foreach (int elt in myLL) ... public static void MergeSort ... LinkedListNodemidL, pos; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Fastcode poll - Should Sort include worst case situations
    ... Quite was regarded Hoare's original Quicksort. ... Reversely sorted data ... Anyway QuickSort is very simple algorithm and it's complexity is precisely analized. ... further detailed retrospective of many QuickSort implementations as well as other sort algorithm will take too much time and space - wikipedia is starting point and give some interesting links for further analyze who is interested. ...
    (borland.public.delphi.language.basm)