public void thisSort() { StrList tmp = returnSort(); for (int i = 0; i <= tmp.getEnd(); i++) { add(tmp.getAt(i)); } }
public StrList returnSort() { StrList returnList = new StrList(); //int length = end; for (int i = 0, loop = end; i <= loop; i++) { int leastIndex = 0; for (int j = 0; j <= end; j++) { if (makeNameCode(getAt(j)) < makeNameCode(getAt(leastIndex))) { leastIndex = j; } } returnList.add(getAt(leastIndex)); delAt(leastIndex); } return(returnList); }
public StrList yuckSort() { StrList returnList = new StrList(); for (char i = 'a'; i <= 'z'; i++) { for (char j = 'a'; j <= 'z'; j++) { for (char k = 'a'; k <= 'z'; k++) { for (int x = 0; x <= end; x++) { if (getAt(x)[0] == i && getAt(x)[1] == j && getAt(x)[2] == k) { returnList.add(getAt(x)); } } } } } return(returnList); }
private static void delName(string name, StrList names) { bool performed = false; int endLoop = names.getEnd(); for (int i = 0; i <= endLoop; i++) { if (names.getAt(i) == name) { names.delAt(i); performed = true; endLoop--; } } if (!performed) { Console.WriteLine("Name not found in the list."); } else { Console.WriteLine(name + " has been deleted from the list."); } }
public static void Main(string[] args) { Console.WriteLine("Welcome to the name sorter!\nPlease enter the file from which you would like to use the names from. -> "); string file = Console.ReadLine(); StrList names = new StrList(); foreach (var name in System.IO.File.ReadAllLines(file)) { //names.add(name); names.sortAdd(name); } //names.lazySort(); //names = names.yuckSort(); //names = names.returnSort(); //names.thisSort(); ////////////////////////////names.bubbleThisSort(); Console.WriteLine(); bool end = false; while (!end) { names.index(); Console.Write("\nWhat would you like to do?\n1. Display the list.\n2. Get the length of the list.\n3. Delete a name.\n4. Display names starting with a given letter.\n5. End the program.\n>"); switch (Console.ReadLine()) { case "1": names.printList(); break; case "2": Console.WriteLine("\nThere are " + (names.getEnd() + 1) + " names in the list."); break; case "3": Console.Write("\nPlease input which name you would like to delete: "); string name = Console.ReadLine(); delName(name, names); break; case "4": Console.Write("\nPlease input a letter: "); names.printWithLetter(Console.ReadLine()[0]); break; case "5": end = true; break; default: Console.WriteLine("That's not a valid input silly"); break; } } /*for (int i = 0; i <= names.getEnd(); i++) * { * Console.WriteLine(names.getAt(i)); * }*/ }