GeckoPrimed

Pinescript Selection Sort Using Arrays

The selection sort algorithm sorts an array by repeatedly finding the smallest element from unsorted array and pushing it to the beginning. Two subarrays are maintained during the execution of the script. One of the subarrays is in a sorted state while the other is in a sorted state. After each iteration of the for loop the sorted list is searched for the next correct element which is then pushed onto the sorted subarray.

Worst case performance : О(n^2) comparisons and O(n)swaps
Best case performance : O(n^2) comparisons and O(n) Swaps
Average performance: О(n^2) comparisons and O(n) Swaps
Worst-case space complexity:О(n) total, O(1) auxiliary

The Pseudocode is given below
procedure selection sort 
   list  : array of items
   n     : size of list

   for i = 1 to n - 1
   /* set current element as minimum*/
      min = i    
  
      /* check the element to be minimum */

      for j = i+1 to n 
         if list[j] < list[min] then
            min = j;
         end if
      end for

      /* swap the minimum element with the current element*/
      if indexMin != i  then
         swap list[min] and list[i]
      end if
   end for
	
end procedure
Açık kaynak kodlu komut dosyası

Gerçek TradingView ruhuyla, bu betiğin yazarı, yatırımcının anlayabilmesi ve doğrulayabilmesi için onu açık kaynak olarak yayınladı. Yazarın eline sağlık! Bunu ücretsiz olarak kullanabilirsiniz, ancak bu kodun bir yayında yeniden kullanımı Kullanım Koşulları ile yönetilir. Bir grafikte kullanmak için favorilere ekleyebilirsiniz.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?