PerlCool,
As you can probably tell, we believe your question to be homework which is very much frowned on if not acknowledged as such (and sometimes even then). It is perfectly possible that you want to know how sorting algorithms work and can't understand perl's source code written in C nor the myriad of explanations online. If that is the case, then make sure you say that.

Learning the pros and cons of merge sort in comparison to a bubble sort is worth pursuing in my opinion. For that reason I am going to give you the tools to write your own bubble sort and that should give you enough knowledge to explore more advanced sorting algorithms. If you get stuck and need help, make sure you are much more forthcoming with what you are doing and why (because I too think this is homework).

The cmp operator will compare two strings and tell you if they are equal or not. If they are not equal, it will tell you which one is greater than the other ASCIIbetically. You can swap the value of two array elements using the following syntax: ($list[0], $list[1]) = ($list[1], $list[0]); Now consider you are compare the first two elements of the list and they are out of order - just swap them. Next, compare the second element, if they are order, swap them. Repeat this process until you reach the end of the list. Start back at the beginning and continue until you go all the way through the list without swapping any elements - then you know it is in sorted order.

Cheers - L~R


In reply to Re: Sorting Arrays Without using SORT function by Limbic~Region
in thread Sorting Arrays Without using SORT function by PerlCool

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.