Ok, I'm working on a program that is supposed to compare each letter
of a string that is put into a stack and a queue. It is supposed to
tell whether or not a word is a palindrome or not. (a palindrome is a
word that spells the same thing backwards/forewards). I have gotten
this much so far:
using System;
using System.Collections;
namespace StackTest
{
public class Tester
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Enter in a string");
string s1=Console.ReadLine();
Console.WriteLine(" ");
Stack st=new Stack();
Queue q1=new Queue();
for(int i=0; i<s1.Length; i++)
{
q1.Enqueue(s1.Substring(i,1));
if(i==s1.Length-1)
{
for(i=0; i<s1.Length; i++)
{
char y=Convert.ToChar(q1.Dequeue());
Console.WriteLine(y);
}
Console.WriteLine(" ");
}
}
for(int i=0; i<s1.Length; i++)
{
st.Push(s1.Substring(i,1));
if(i==s1.Length-1)
{
for(i=0; i<s1.Length; i++)
{
Char x=Convert.ToChar(st.Pop());
Console.WriteLine(x);
}
}
}
string qu=Convert.ToString(q1);
string sta=Convert.ToString(st);
if(qu==sta)
{
Console.WriteLine("PALINDROME");
}
if(qu!=sta)
{
Console.WriteLine("NOT A PALINDROME");
}
}
}
}
Every string that i enter has the output of "NOT A PALINDROME" I have
played with this for a while now and am just getting tired of it. I
dont know what i have that i dont need, or what i need that i dont
have.. but any help would be appreciated.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---