422,024 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,024 IT Pros & Developers. It's quick & easy.

C# Stacks & Queues

P: 2
I looked at the old subject again. Link:https://bytes.com/topic/c-sharp/answ...-queue-compare Although I did try, I could not run the code.Is this code capable of working? I want my homework and help.


is it necessary to create a second class?
We have always seen classes as creating a second class.
This is the part that forces me.The assignment is short and I do not have much time.Thank you very much in advance.

Code:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HW1VY16253601
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter in a string");
  14.             string s1 = Console.ReadLine();
  15.             Console.WriteLine(" ");
  16.             Stack<string> st = new Stack<string>();
  17.             Queue<string> q1 = new Queue<string>();
  18.  
  19.  
  20.  
  21.             for (int i = 0; i < s1.Length; i++)
  22.             {
  23.  
  24.                 q1.Enqueue(s1.Substring(i, 1));
  25.                 if (i == s1.Length - 1)
  26.                 {
  27.                     for (i = 0; i < s1.Length; i++)
  28.                     {
  29.                         char y = Convert.ToChar(q1.Dequeue());
  30.                         Console.WriteLine(y);
  31.                     }
  32.                     Console.WriteLine(" ");
  33.                 }
  34.             }
  35.             for (int i = 0; i < s1.Length; i++)
  36.             {
  37.                 st.Push(s1.Substring(i, 1));
  38.                 if (i == s1.Length - 1)
  39.                 {
  40.                     for (i = 0; i < s1.Length; i++)
  41.                     {
  42.                         Char x = Convert.ToChar(st.Pop());
  43.                         Console.WriteLine(x);
  44.                     }
  45.                 }
  46.             }
  47.             string qu = Convert.ToString(q1);
  48.             string sta = Convert.ToString(st);
  49.             if (qu == sta)
  50.             {
  51.                 Console.WriteLine("PALINDROME");
  52.             }
  53.             if (qu != sta)
  54.             {
  55.                 Console.WriteLine("NOT A PALINDROME");
  56.             }
  57.         }
  58.     }
  59. }
Oct 8 '17 #1
Share this Question
Share on Google+
2 Replies


P: 2
Expand|Select|Wrap|Line Numbers
  1. if (qu == sta)
  2. {
  3. Console.WriteLine("PALINDROME");
This is not working. I need to make arrangements for it to work.I expect your answers.
Oct 8 '17 #2

Frinavale
Expert Mod 5K+
P: 9,712
The Console.WriteLine method works when you are implementing a Console application.

Did you create a Console application project to test this with?

Outside of the obvious "Console.WriteLine" not working...

What are you trying to do?
What type of structures are you expected to use to solve your problem?
Oct 10 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.