private static int[] merge(int[] left, int[] right) {

		// Lengths of both lists
		int leftLength = left.length;
		int rightLength = right.length;
		int[] result = new int[leftLength + rightLength];

		// Sets of indexes
		int idx = 0;
		int leftIdx = 0;
		int rightIdx = 0;

		// Goes through both lists (as long as there are any elements in either of them)
		while (leftLength > 0 || rightLength > 0) {

			// Checks if both lists have elements
			if (leftLength > 0 && rightLength > 0) {
				if (left[leftIdx] <= right[rightIdx]) {
					result[idx++] = left[leftIdx++];
					--leftLength;
				}
				else {
					result[idx++] = right[rightIdx++];
					--rightLength;
				}
			}
			// Add the current element of the left list
			else if (leftLength > 0) {
				result[idx++] = left[leftIdx++];
				--leftLength;
			}
			// Add the current element of the right list
			else if (rightLength > 0) {
				result[idx++] = right[rightIdx++];
				--rightLength;
			}
		}

		return result;
	}