How to resolve the algorithm Sorting algorithms/Patience sort step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sorting algorithms/Patience sort step by step in the 11l programming language

Table of Contents

Problem Statement

Sort an array of numbers (of any convenient size) into ascending order using   Patience sorting.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sorting algorithms/Patience sort step by step in the 11l programming language

Source code in the 11l programming language

F patience_sort(&arr)
   I arr.len < 2 {R}

   [[T(arr[0])]] piles
   L(el) arr
      L(&pile) piles
         I pile.last > el
            pile.append(el)
            L.break
      L.was_no_break
         piles.append([el])

   L(i) 0 .< arr.len
      V min = piles[0].last
      V minPileIndex = 0
      L(j) 1 .< piles.len
         I piles[j].last < min
            min = piles[j].last
            minPileIndex = j
      arr[i] = min
      V& minPile = piles[minPileIndex]
      minPile.pop()
      I minPile.empty
         piles.pop(minPileIndex)

V iArr = [4, 65, 2, -31, 0, 99, 83, 782, 1]
patience_sort(&iArr)
print(iArr)

V cArr = [‘n’, ‘o’, ‘n’, ‘z’, ‘e’, ‘r’, ‘o’, ‘s’, ‘u’, ‘m’]
patience_sort(&cArr)
print(cArr)

V sArr = [‘dog’, ‘cow’, ‘cat’, ‘ape’, ‘ant’, ‘man’, ‘pig’, ‘ass’, ‘gnu’]
patience_sort(&sArr)
print(sArr)

  

You may also check:How to resolve the algorithm Multi-dimensional array step by step in the Klingphix programming language
You may also check:How to resolve the algorithm Munchausen numbers step by step in the BASIC programming language
You may also check:How to resolve the algorithm Hostname step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Stream merge step by step in the ATS programming language
You may also check:How to resolve the algorithm ABC problem step by step in the TXR programming language