Labor – Char-Array: Sorting + Shuffling + more
see Arrays sortieren — Selection Sort, Bubble Sort, etc. for details!
-
Constructor(..) … transforms given String to char-Array. If capacity too small, use only the fitting part of txt. Set
freeIdxaccordingly. -
replaceArray(..) … replace the attribute with the given array.
-
selectionSort() … sorts the (valid part of)
chars-Array with Selectionsort (using helper methodfindMinValPos(..)andswap(..)) -
bubbleSort() … sorts the (valid part of)
chars-Array with Bubblesort (using helper methodoneBubble(..)andswap(..)!) -
shuffle() … mix the chars by going through the array and swapping with a randomly defined other position. Use
swap(..)for that! -
invert() … swap first with last, second with one before last, etc. (use
swap(..)) -
subArray(..) … create a new array of exactly needed length (calculated from
startIdxandendIdxExcl) and fill it with the proper values from the Array attributechars. If both indices are outside valid range (freeIdx!), return array of length 0. IfendIdxExcloutside, usefreeIdx, ifstartIdxoutside, use 0 instead. (usable e.g. to cut out a specific word by finding the spaces around it) -
toString … create a String from the array (without separating elements)
-
isArrSorted(..) … checks if array is sorted by checking if every pair of neighbors hs the right relation
-
swap(..) … exchange the values at the given indices
-
printArray(..) … static method to print given array (up to the given freeIdx), a title, cols (= elements per row). The
titleis printed above to give a hint what operation was done/what is the state with the array.