Don't use
ArrayList
. This type is obsolete since generics were introduced in v.2.0. Why do you need all those problems with type casting?
Instead, use the generic class
System.Collections.Generic.List<T>
,
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[
^]. For sorting use some of the
Sort
methods. The sorting can be done using default comparison rules (default comparer), or you can define custom comparison using custom-defined delegate of the type
System.Comparison<T>
or by defining a class implementing the interface
System.Collections.Generic.IComparer<T>
. The range sorting is also available.
Alternatively, you can use a list which is kept sorted by a key,
System.Collections.Generic.SortedList<TKey, TValue>
, it can be constructed using default comparer or a custom one in the form of
System.Collections.Generic.IComparer<T>
.
For a two-dimensional jagged array with the element type
T
use the list type
List<List<T>>
. For sorting of such thing you will certainly need a custom comparer, which is quite easy to implement.
I don't know how comparison will help you to solve the Hanoi Tower problem — there are very simple iterative and recursive algorithms, both of them, see
http://en.wikipedia.org/wiki/Tower_of_Hanoi[
^].
—SA