I am having an issue printing a sorted list after creating a bubble sort. I am able to print the unsorted list, however, I'm not sure how to actually pass in the unsorted list to my Bubble sort method or if I even have to. The list that I am printing and trying to sort is a .csv file that I was supposed to read in from a separate method. This is the code I have so far.
switch (menuChoice)
{
case 1:
ReadFile(fpath);
Console.ReadKey();
Console.Clear();
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
}
}
private static void BubbleSort(List<string> bList)
{
int listLength = bList.Count();
bool swapped = false;
do
{
for (int i = 0; i <= listLength; i++)
{
int newListLngth = bList[i - 1].CompareTo(bList[i]);
if (newListLngth > 0)
{
Swap(bList, i, i - 1);
swapped = true;
}
}
} while (!swapped);
}
static List<string> MergedSort(List<string> mergedList)
{
List<string> merger = new List<string>();
if (mergedList.Count <= 1)
{
return mergedList;
}
return merger;
}
static void Swap(List<string> numbers, int index1, int index2)
{
string temp = numbers[index1];
numbers[index1] = numbers[index2];
numbers[index2] = temp;
}
private static void ReadFile(string filePath)
{
using (StreamReader sr = new StreamReader(filePath))
{
char delimiter = ',';
string comicText = File.ReadAllText(filePath);
string[] data = comicText.Split(delimiter);
List<string> names = data.ToList();
for (int i = 0; i < names.Count; i++)
{
Console.WriteLine(names[i]);
}
}
}
}