On 5/30/2010 8:43:49 AM, Pauli Lindgren wrote:
>On 5/25/2010 11:35:51 PM, peter rejto
>wrote:
>There is nothing in Merge Sort or any
>other algorithms that would limit it to
>specific data type such as list. The
>term "list" is used in the Wikipedia
>article just to refer any collection of
>objects to be sorted, whether it is an
>array, text file or whatever.
>
>>
>>Now I have a very simple question. Can I
>>sort a list in Vedit ? For example,
>>can I sort the numbers, {1,5,3} in Vedit
>>?
>>
>>In other words my problem is to sort a
>>row, from left to right in Vedit ?
>
>To sort a comma separated list (from
>cursor position to end of file), you
>could do for example:
>#1 = CPReplace(",", "|N", ALL)Sort(#1,
>EOB_pos)GP(#1)Replace("|N", ",", ALL)
>However, sorting numeric values may need
>more works, since there is no numeric
>option in the sort command.
>
>Pauli,
Thanks for putting me on the right track. After some, experimentation, I did put the following two lines into my USER_MNU:
Transpose Highlighted Line(Pauli Lindgren)
Goto_Pos( Min(Block_Begin,Block_End) ) Replace_Block(",","|N",BB,BE,ALL)
(Well, the above three lines is only two in my USER_MNU.)
This converts the line into a column. Then, the Vedit Menu Command, {Edit, Sort, Sort lines(keys, options)...}
did the actual sorting.
You also mention additional numerical work. I forgot to tell you that I am mainly interested in the case of my CSV line having positive integer entries. I take the additional work refers to the general case.
I like your idea of replacing the comma by the end of line character very much. In fact, I would like to pursue two generalizations as well. Since I do not have a programming background, I shall try to pursue only the first one. I do hope that somebody wil have an interest in the second one:
1.: According to Chapter 4 of the Vedit User Manual, the
{Edit, Sort, Sort lines(keys, options)...} command uses the SORT_MERGE.VDM macro. Hence, I can edit this menu
command by editing this macro. What do you think would be a good name for this option ?
2.: I have been wondering, ever since Scott Lambert wrote his beautiful arithmetic macros, about importing spreadsheet commands into Vedit. To be sure, I know that Vedit is not a spreadsheet! At the same time, Scott has shown that some special cases of some spreadsheet commands, can be imported.
It seems to me, that you have just shown me, how to import this special case of the transpose command. This special case is general enough for me. Specifically, it allows me to find the sum of the six best quizzes out of eleven quizzes.
Once again, a big thank you.
-peter.
|
|