public static void Main()
WordClass wordClass = new WordClass();
string[] words = wordClass.words;
int wordsCount = words.Length;
Console.WriteLine("Current dictionary of words:");
for(int i = 0; i < wordsCount; i++)
Console.Write(words[i] + " ");
Console.WriteLine("What word are we targeting to find the predecessor? ");
string targetWord = Console.ReadLine();
WordClass.get_previous_word(targetWord, words, wordsCount);
Console.WriteLine("Search again? (Y/N) ");
replay = Console.ReadLine();
} while (string.Equals(replay, "Y", StringComparison.InvariantCultureIgnoreCase));
private readonly string[] _words = { "apple", "peanut butter", "interview", "monkey", "superhero", "interventions" };
public string[] words {get{return _words;}}
public static void get_previous_word(string pTargetWord, string[] ppUnsortedDictionary, int unsortedDictionaryWordCount)
string predecessor = "unavailable as the target word was not found.";
Array.Sort(ppUnsortedDictionary);
for (int index = 0; index < unsortedDictionaryWordCount; index++)
if (ppUnsortedDictionary[index] == pTargetWord)
predecessor = ppUnsortedDictionary[index-1];
predecessor = "unavailable as the target word was first in list";
Console.WriteLine("**The predecessor to " + pTargetWord + " is " + predecessor);