sorting array in mips (assembly)

This link explains how to print to the screen in a MIPS simulator like QTSPIM or MARS. As for the code, there were a few bugs. The line li $a0, 0 is overwriting the work done by the initial la $a0, Array instruction because the li is setting the base address of your array to 0. Instead, you should move the la instruction into the loop so … Read more

Sort ArrayList of custom Objects by property

Since Date implements Comparable, it has a compareTo method just like String does. So your custom Comparator could look like this: The compare() method must return an int, so you couldn’t directly return a boolean like you were planning to anyway. Your sorting code would be just about like you wrote: A slightly shorter way to write all this, if you don’t need to reuse your comparator, is to … Read more

How to sort an array in Bash

You don’t really need all that much code: Supports whitespace in elements (as long as it’s not a newline), and works in Bash 3.x. e.g.: Note: @sorontar has pointed out that care is required if elements contain wildcards such as * or ?: The sorted=($(…)) part is using the “split and glob” operator. You should … Read more