// bubble sort static List <DataSetEl> bubbleSort(List <DataSetEl> dataset) { int i, j; for (i = 0; i < dataset.Count - 1; i++) { for (j = 0; j < dataset.Count - i - 1; j++) { if (dataset[j].room_id > dataset[j + 1].room_id) { DataSetEl temp = dataset[j]; dataset[j] = dataset[j + 1]; dataset[j + 1] = temp; } } } return(dataset); }
static void readFileContent(ref List <DataSetEl> dataSetArray) { try { int counter = 0; string line; StreamReader file = new StreamReader("dataset_ordered_desc.txt"); while ((line = file.ReadLine()) != null && counter < numOfLines) { if (counter > 0) { string[] lineSplited = line.Split('\t'); DataSetEl aux = new DataSetEl(); aux.room_id = long.Parse(lineSplited[0]); aux.host_id = long.Parse(lineSplited[1]); aux.room_type = lineSplited[2]; aux.country = lineSplited[3]; aux.city = lineSplited[4]; aux.neighborhood = lineSplited[5]; aux.reviews = lineSplited[6]; aux.overall_satisfaction = lineSplited[7]; aux.accommodates = lineSplited[8]; aux.bedrooms = lineSplited[9]; aux.price = lineSplited[10]; aux.property_type = lineSplited[11]; dataSetArray.Add(aux); } counter++; } } catch (IOException e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
// quick sort static int partition(List <DataSetEl> dataset, int minor, int max) { long pivô = dataset[max].room_id; int i = (minor - 1); for (int j = minor; j < max; j++) { if (dataset[j].room_id < pivô) { i++; DataSetEl temp = dataset[i]; dataset[i] = dataset[j]; dataset[j] = temp; } } DataSetEl aux = dataset[i + 1]; dataset[i + 1] = dataset[max]; dataset[max] = aux; return(i + 1); }