locked
How to sort an Array RRS feed

  • Question

  • User337566521 posted

    Hi

    there is a  n arrary

    a={19,15,12,9,4,22,1,5,}

    How can I sort the array without using sort Method in c#

    Monday, June 6, 2011 2:00 PM

Answers

  • User-125547262 posted

    May I ask why ? The framework already provides you an efficient way to sort. Why not use it?

    If you want to implement something yourself take a look at this :)

    http://en.wikipedia.org/wiki/Bubble_sort

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 6, 2011 2:04 PM
  • User1446927574 posted

    Try Linq

    int[] a = {1, 33, 4, 66, 7, 8, 33};
    a = a.OrderBy(i => i).ToArray();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 6, 2011 2:10 PM

All replies

  • User-125547262 posted

    May I ask why ? The framework already provides you an efficient way to sort. Why not use it?

    If you want to implement something yourself take a look at this :)

    http://en.wikipedia.org/wiki/Bubble_sort

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 6, 2011 2:04 PM
  • User1508394307 posted

    For example like this.

    Monday, June 6, 2011 2:06 PM
  • User198012145 posted

    there are two ways to do that

    1. you can use the inbulit function like  Array.Sort(a);

    2. you can define your own function for this, in which you define your loops and logics etc.

    Monday, June 6, 2011 2:06 PM
  • User1446927574 posted

    Try Linq

    int[] a = {1, 33, 4, 66, 7, 8, 33};
    a = a.OrderBy(i => i).ToArray();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 6, 2011 2:10 PM
  • User-789378311 posted

    You can loop through the array or use LINQ to sort or use Arrays' built in sort function.

    Monday, June 6, 2011 2:46 PM
  • User-1910946339 posted

    Here you go

    a = {1,4,5,9,12,15,19,22}

    We don't do your homework for you in this forum

    Monday, June 6, 2011 7:25 PM
  • User1288683547 posted

    We don't do your homework for you in this forum

    Laughing

    Tuesday, June 7, 2011 12:42 AM