this is suppose to be infix to postfix converter
ramyking
0
Newbie Poster
Recommended Answers
Jump to PostThe main problem is that all your code is in one function, making it difficult to reason about. You need to design your code around the limitations of your brain.
Also, you end up with an empty stack because you never check if your stack is empty.
Jump to PostIt doesn't have data in it. What makes you say it has data in it? If it had data in it, the exception wouldn't be thrown.
I don't see any place in your code where you check to see if the stack has data in it.
Jump to Postwhile (revstack.Peek().ToString() == "+" ||
revstack.Peek().ToString() == "-" ||
revstack.Peek().ToString() == "*" ||
revstack.Peek().ToString() == "/")
stack.Push(revstack.Pop());I am still with your first code: if revstack pops it can find empty and you get an error.
You cannot pop anything from an empty stack.
Jump to PostIMHO why use a loop here? Better use an if I think. Check with the Empty method if your stack is empty or not!
Jump to PostYou can't peek if you have an empty stack. (Can you? Oh god please tell me it doesn't return null.)
All 20 Replies
ramyking
0
Newbie Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
ramyking
0
Newbie Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
ramyking
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
ramyking
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
ramyking
0
Newbie Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
ramyking
0
Newbie Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
ramyking
0
Newbie Poster
ramyking
0
Newbie Poster
harishan
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
أحمد_9
0
Newbie Poster
ddanbe
2,724
Professional Procrastinator
Featured Poster
أحمد_9
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.