2017-11-19 2 views
0

아래의 코드를 작동시키고 싶습니다만, 빈 메서드를 실행하는 방법을 정확히 모르겠습니다. 정수 배열을 정렬하는 논리가 있어야하지만 어떻게 작동하는지 이해할 수 없습니다.배열의 정수를 정렬하는 메서드를 호출합니다.

https://dotnetfiddle.net/U1pQ9B

using System; 
class Program 
{ 
    static void SortAscending(int[] a, out int []b) 
    { 
     // Write your code here 
    } 

    static void Main(string[] args) 
    { 
     Console.WriteLine("Enter the Array Size :");  // 1 - Enter the array Length 
     int ArraySize = int.Parse(Console.ReadLine());  // 2 - Put the Number for array Length in variable int ArraySize 
     int[] Arr = new int[ArraySize];     // 3 - put the number of the input as a default Length value 
     int[] Arr_Ascending;        // 4 - initialize an array Arr_Ascending 
     Console.WriteLine("Enter Input Array Elements :"); // 5 - 

     for (int i = 0; i < ArraySize; i++) 
     { 
      Console.WriteLine("Enter the Element number " + (i + 1)+" :"); 
      Arr[i] = int.Parse(Console.ReadLine()); 
     } 

     SortAscending(Arr,out Arr_Ascending); 
     Console.Write("Ascending :"); 

     for (int i = 0; i < Arr.Length; i++) 
     { 
      Console.Write(Arr_Ascending[i] + " "); 
     } 

     Console.WriteLine(); 
    } 
} 
+0

처음부터 정렬 알고리즘을 구현하는 귀하의 작업인가? 그렇다면 거품 정렬과 같은 간단한 것을 찾아보고 구현할 수 있습니다. 기존의 구현물을 원한다면'Array.Sort'를 사용할 수 있습니다. – fuglede

+1

'// 여기 Wtrie your code here '라고 말한 후, 적절한 질문을 가지고 우리에게 연락하십시오. 그리고 [ask]를 읽고 [tour]를 가져 가라. – Plutonix

답변

1

당신은 LINQ 사용할 수 있습니다

가함으로써 라인

SortAscending(Arr,out Arr_Ascending); 

를 교체

Arr_Ascending = Arr.OrderBy(x => x).ToArray(); 

가 참조하는 것을 잊지 마세요 패키지 System.Linq을 줬어

업데이트 바이올린 : https://dotnetfiddle.net/PNKp70

+1

정말 고마워요! 감사합니다, Linq는 약간 거래 같습니다! – Asparuh

관련 문제