How to resolve the algorithm Sort disjoint sublist step by step in the AutoHotkey programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sort disjoint sublist step by step in the AutoHotkey programming language

Table of Contents

Problem Statement

Given a list of values and a set of integer indices into that value list, the task is to sort the values at the given indices, while preserving the values at indices outside the set of those to be sorted. Make your example work with the following list of values and set of indices: Where the correct result would be: In case of one-based indexing, rather than the zero-based indexing above, you would use the indices {7, 2, 8} instead. The indices are described as a set rather than a list but any collection-type of those indices without duplication may be used as long as the example is insensitive to the order of indices given.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sort disjoint sublist step by step in the AutoHotkey programming language

Source code in the autohotkey programming language

Sort_disjoint_sublist(Values, Indices){
    A := [], B:=[], C := [], D := []
    for k, v in Indices
        A[v] := 1 , B[Values[v]] := v
    for k, v in A
        C.Push(k)
    for k, v in B
        D.Push(k)
    for k, v in D
        Values[C[A_Index]] := D[A_Index]
    return Values
}


Values := [7, 6, 5, 4, 3, 2, 1, 0]
Indices := [7, 2, 8]
Values := Sort_disjoint_sublist(Values, Indices)
for k, v in Values
    output .= v ", "
MsgBox % "[" Trim(output, ", ") "]"					; show output


  

You may also check:How to resolve the algorithm Reflection/List properties step by step in the Factor programming language
You may also check:How to resolve the algorithm Count the coins step by step in the Quackery programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Ruby programming language
You may also check:How to resolve the algorithm Fibonacci word/fractal step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the Processing programming language