473,657 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Stacks & Queues

2 New Member
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
2 1885
mtmecaz
2 New Member
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
9,735 Recognized Expert Moderator Expert
The Console.WriteLi ne 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.WriteL ine" 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

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

Similar topics

7
5017
by: Anand Pillai | last post by:
The standard Python Queue module, allows to generate queues that have no size limit, by passing the size argument as <= 0. q = Queue(0) In a multithreaded application, these queues could be useful when you have many threads using the queue for data access and synchronization. Is there a performance hit when one uses an 'infinite' queue
3
2278
by: Michael Sparks | last post by:
Hi, I'm posting a link to this since I hope it's of interest to people here :) I've written up the talk I gave at ACCU Python UK on the Kamaelia Framework, and it's been published as a BBC R&D White Paper and is available here: * http://www.bbc.co.uk/rd/pubs/whp/whp113.shtml
4
3199
by: Ice | last post by:
Hi there, I'm not sure if this is the right group for this- If it isn't, could anyone point me in the right direction? For our data structures exam, we are usually asked to implement the structures we've studied (ofcourse in c++). For e.g. implementations of a stack could be paranthesis matching/evaluating polish notation etc. Can anyone suggest implementations/usage of the above mentioned data
7
2361
by: GrandpaB | last post by:
While writing this plea for help, I think I solved my dilemma, but I don't know why the statement that solved the problem is necessary. The inspiration for the statement came from an undocumented VB example I found on the web. I would be most appreciative if someone could explain why this statement is necessary and what does it do? MyArt = New Art ' **** ??????? ****
10
2120
by: Rich Kucera | last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version configurations inevitable Will have to wait to see what the impact of problems such as http://bugs.php.net/bug.php?id=33643 to the application world. We may wait for a suitable popular resolution and jump to that version in the future. There's already a rift between PHP4 and PHP5, and then further developments such as these create another, splitting the camp into 4....
1
1491
by: romel | last post by:
Hi to all evryone? Anyone can help me regarding the program that i have?...i got problems about our topic that all about the QUEUE & STACKS.... I am begging you all that send me some codes regarding this topic that i mensioned above...... I am waiting for your concerned and reply.. THANKS IN ADVANCE!!!!
5
10753
by: ravi | last post by:
Can any body tell me How to implement a stack using two queues Thax in advance
0
1058
by: phanipep | last post by:
4 applications of stacks and queues. Justify your choices.
11
5918
mia023
by: mia023 | last post by:
Hello everyone. Assume that we have previously defined the following class StockPurchase that has the following as instance variables a) The name of the stock (a string) b) The number of shares of a stock (an int) c) The purchase price (can be a decimal)
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.