Posts

Showing posts with the label Queue

Donate

Example Of IsPalindrome Generic Function Using Queue In C#

Hello, Excerpt from .NET 4.0 Generic's Guide , there's an example on testing whether a string is Palindrome using a Stack<T> object. I decided to create a a Queue<T> based method. One additional tip was to reverse the Queue object. See sample function below: public static bool IsPalindromic<T>(IEnumerable<T> inputSequence) where T : IComparable { Queue<T> buffer = new Queue<T>(); foreach (T element in inputSequence) { buffer.Enqueue(element); } buffer = new Queue<T>(buffer.Reverse()); for ( int i = 0; i < inputSequence.Count(); i++) { if (buffer.Dequeue().CompareTo(inputSequence.ElementAt(i)) == 0) { continue ; } else return false ; } return true ; } Source Code: Example Of IsPalindrome Generic Function Using Queue In C# That

Donate