Currently I have built an array of 1200 instances of the 'Element' class. Each one is populated automatically via its constructor (scraping data line by line from 9 different arrays (the arrays originate from 9 different text files)).
public class Element
{
public int elementDay;
public string elementMonth;
public int elementYear;
public string elementTime;
public int elementTimestamp;
public string elementRegion;
public float elementLongitude;
public float elementLatitude;
public float elementMagnitude;
public float elementDepth;
public float elementIris_Id;
public Element(int[] day, string[] month, int[] year, string[] time, int[] timestamp, string[] region, float[] longitude, float[] latitude, float[] magnitude, float[] depth, float[] iris_Id, ref int counter)
{
elementDay = day[counter];
elementMonth = month[counter];
elementYear = year[counter];
elementTime = time[counter];
elementTimestamp = timestamp[counter];
elementRegion = region[counter];
elementLongitude = longitude[counter];
elementLatitude = latitude[counter];
elementMagnitude = magnitude[counter];
elementDepth = depth[counter];
elementIris_Id = iris_Id[counter];
counter++;
}
public static void CreateElementList(Element[] arrayElements, int[] day, string[] month, int[] year, string[] time, int[] timestamp, string[] region, float[] longitude, float[] latitude, float[] magnitude, float[] depth, float[] iris_Id, ref int counter)
{
for (int i = 0; i < 1200; i++)
{
arrayElements[i] = new Element(day, month, year, time, timestamp, region, longitude, latitude, magnitude, depth, iris_Id, ref counter);
}
}
Right now I need to find a way of sorting these objects by certain properties.
A working example of what I want is: Array.Sort(arrayElements, delegate (Element x, Element y) { return y.elementDay.CompareTo(x.elementDay); });
However I cannot use this as it is an in-built function. I'm trying to implement a Quicksort algorithm to sort these objects by 'day' but I do not know if it is possible to do such a thing with an array of elements as I only know how to do this with a simple integer array. The end goal is to be able to sort by any of the properties and for the entire array of elements to be sorted with respect to the chosen property.
Please keep in mind this is homework, so please do not give me the full solution, I mainly want to know if it is possible/worth my time, or should I simply try another approach?