//****************************************************************************************// //************************************* HANDLE DATA **************************************// //****************************************************************************************// static string HandleData(Dictionary <int, MySteps> dict) { var returnValue = new MyRetunValue(); string anwser = ""; CheckNext :; Console.WriteLine("************* HandleData --> HandleDataOneScan *****************"); returnValue = HandleDataOneScan(dict); anwser += returnValue.Anwser.ToString(); Console.WriteLine("************* HandleData --> RemoveLine *****************"); dict = RemoveLine(dict, returnValue); if (dict.Count > 0) { //Console.ReadKey(); goto CheckNext; } else { anwser += returnValue.SecondStep.ToString(); } return(anwser); }
//****************************************************************************************// //************************************* REMOVE LINE **************************************// //****************************************************************************************// static Dictionary <int, MySteps> RemoveLine(Dictionary <int, MySteps> dict, MyRetunValue lastAnwser) { var items = from pair in dict orderby pair.Value.FirstStep ascending select pair; //Remove line from dictonary foreach (KeyValuePair <int, MySteps> pair in items) { if (pair.Value.FirstStep == lastAnwser.FirstStep) //&& pair.Value.SecondStep == lastAnwser.SecondStep) { Console.WriteLine(" Remove: {0}: {1} : {2}", pair.Key, pair.Value.FirstStep, pair.Value.SecondStep); dict.Remove(pair.Key); } } return(dict); }
//****************************************************************************************// //************************** HANDLE DATA ONE SCAN ****************************************// //****************************************************************************************// static MyRetunValue HandleDataOneScan(Dictionary <int, MySteps> dict) { var returnValue = new MyRetunValue(); bool itemFound; int i, j; char[,] itemsFound = new char[100, 2]; char nextLetter = new char(); char firstLetter = new char(); //Order by firststeps var items = from pair in dict orderby pair.Value.FirstStep ascending select pair; i = 0; //loop to dictonary foreach (KeyValuePair <int, MySteps> pair in items) { itemFound = false; //loop to diconary foreach (KeyValuePair <int, MySteps> pair2 in items) { //check if value exist in second colum if (pair.Value.FirstStep == pair2.Value.SecondStep) { itemFound = true; } } //If not found in second colum if (itemFound == false) { itemsFound[i, 0] = pair.Value.FirstStep; itemsFound[i, 1] = pair.Value.SecondStep; i += 1; } } nextLetter = 'Z'; //Determine first and next letter for (j = 0; j < 1; j++) { Console.WriteLine(" Option found: {0}, {1}", itemsFound[j, 0], itemsFound[j, 1]); if (itemsFound[j, 1] <= nextLetter) { firstLetter = itemsFound[j, 0]; nextLetter = itemsFound[j, 1]; } } returnValue.Anwser = firstLetter; returnValue.FirstStep = firstLetter; returnValue.SecondStep = nextLetter; Console.WriteLine(" Return: Firstletter: {0}, Secondletter: {1}, Anwser: {2}", returnValue.FirstStep, returnValue.SecondStep, returnValue.Anwser); return(returnValue); }