public long runSortWithCounter(ElementList<E> L, long keycount) {
		ElementList<E> L1 = new ElementList<E>();	// L1 contains elements < pivot
		ElementList<E> L2 = new ElementList<E>();	// L1 contains elements > pivot
		ElementList<E> Lh = new ElementList<E>();	// L1 contains elements == pivot

		if (!L.isEmpty() && L.first().next != null) {
			int H = L.last().element.getKey();
			for (ListNode<E> iter = L.first(); iter != null; iter = iter.next) {
				if (iter.element.getKey() < H) {
					L1.appendNode(iter);
				} else if (iter.element.getKey() > H) {
					L2.appendNode(iter);
				} else {
					Lh.appendNode(iter);
				}
				keycount += 2;
			}
			L1.unlinkAfterLast();
			L2.unlinkAfterLast();
			Lh.unlinkAfterLast();
			// if L1 size > 1: sort L1 recursively
			if (!L1.isEmpty() && L1.first().next != null) {
				keycount = runSortWithCounter(L1, keycount);
			}
			// if L2 size > 1: sort L2 recursively
			if (!L2.isEmpty() && L2.first().next != null) {
				keycount = runSortWithCounter(L2, keycount);
			}
			// link all three lists after sorting
			L1.appendList(Lh);
			L1.appendList(L2);
			L.setAs(L1);
		}
		return keycount;
	}