the assignment is to create a class library for manipulating ConsLists. I haven't found a lot of resources on ConsLists, and I hadn't studied them or recursion before we were assigned this project. That said, this is a (non-functional) method that is supposed to store a ConsList of values less than an int p in an array at index 0, values equal in an array at 1, and values greater in an array 2, then return the array. So:
public static ConsList<int>[] Partition(ConsList<int> list, int p)
{
ConsList<int>[] arr = new ConsList<int>[3];
int index;
if (list != null)
{
if (list.Head < p) index = 0;
else if (list.Head == p) index = 1;
else index = 2;
arr[index] = new ConsList<int>(list.Head, null);
arr = Partition(list.Tail, p);
}
return arr;
}
Can anybody point me in the right direction?