static void Main(string[] args) { CSTack aList = new CSTack(); string ch; string word = "sees"; bool isPalindrome = true; for (int x = 0; x < word.Length; x++) { aList.push(word.Substring(x, 1)); } int pos = 0; while (aList.count > 0) { ch = aList.pop().ToString(); if (ch != word.Substring(pos, 1)) { isPalindrome = false; break; } pos++; } if (isPalindrome) { Console.WriteLine($"{word} is a palindrome."); } else { Console.WriteLine($"{word} is not a palindrome."); } }
static void Main(string[] args) { CSTack aList = new CSTack(); string ch; string testWord = "seed"; bool isPalindrome = true; // push test word on to the stack for (int x = 0; x < testWord.Length; x++) { aList.push(testWord.Substring(x, 1)); } int pos = 0; // while removing test word letters from the stack, check to see if letters match while (aList.count > 0) { ch = aList.pop().ToString(); if (ch != testWord.Substring(pos, 1)) // palindrome matching occurs here { isPalindrome = false; break; } pos++; } if (isPalindrome) { Console.WriteLine($"{testWord} is a palindrome."); } else { Console.WriteLine($"{testWord} is not a palindrome."); } }