stack

how do I reverse a stack using another stack in java [closed]

北城以北 提交于 2019-12-31 05:41:09
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Hi I am trying to reverse a stack(one I coded myself) using another empty stack. For some reason it is not working properly. Can anyone help me with this ? public static void main(String[] args) { Stack stack1 = new Stack(); //filling the stack with numbers from 0 to 4 for(int i = 0; i < Constants.MAX_ELMNTS; i+

How to calculate output of Infix-Expression by using stacks in C#

白昼怎懂夜的黑 提交于 2019-12-31 05:29:12
问题 I already found different solutions on Stackoverflow, but there were some things I didn´t understand. Whats the best method to calculate the Output of e.g.: ((1+(4*(2+3)))+((2+3)*(4*5))) ? My method looks as following, but I know there are lots of mistakes in it: public static int ComputeInfix(string infix) { Stack<char> operatorstack = new Stack<char>(); Stack<int> operandstack = new Stack<int>(); for(int j = 0; j < infix.Length; j++) { char c = infix[j]; if (c => 0 && c <= 9) { operandstack

Java - Printing a message when data exceeds limit?

断了今生、忘了曾经 提交于 2019-12-31 05:28:10
问题 I've got my code working, it's not pretty but it doe's the job :) Now I want to write a piece of code that stops the data from being loaded if there is 19 or more pieces of data in the text file and then display a message saying Invalid input for example. I'm not sure how to do this so any help would be appreciated. package stackandqueue; import java.util.*; import java.util.Stack; import java.util.Queue; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io

Variable sized array on the stack [duplicate]

隐身守侯 提交于 2019-12-31 05:19:36
问题 This question already has an answer here : g++ variable size array no warning? (1 answer) Closed 2 years ago . It is my understanding that in C and C++ , we create data-structures whose size is known at compile time on the stack and we use the heap (malloc-free / new-delete) for things whose size is not known at compile time and is decided at run-time.Why then , does my g++ compiler allow me to do something like the following code snippet. int main(void) { int n ; cin >> n ; // get the size

Infix to Postfix using stack

瘦欲@ 提交于 2019-12-31 03:38:07
问题 My lecturer gave me an assignment to create a program to convert an infix expression to postfix using Stack. I've made the stack classes and some functions to read the infix expression. But this one function, called inToPos(char string[]) which is responsible to convert the inFix expression in the string inFix to the post fix expression in the string postFix using stacks, is creating a breakpoint. Can you guys help me out and tell me what I'm doing wrong? These are my codes that badly needs

Error: deque iterator not dereferenceable

删除回忆录丶 提交于 2019-12-31 02:15:28
问题 I'm trying to create a program that converts an arithmetic expression from infix to postfix form. As long as I don't call the "infixToPostFix" function, the program runs fine. But when I try to run the following code, I get a crash and error "deque iterator not dereferenceable". I can't find any dereferencing operators, so I'm not sure what's wrong: // infixToPostfixTest.cpp #include "Token.h" #include <iostream> #include <vector> #include <stack> using namespace std; // infix to postfix

C++ Strange constructor behaviour

你。 提交于 2019-12-30 21:38:10
问题 Can anybody explain to me the difference between Complex a; and Complex b(); ? #include<iostream> class Complex { public: Complex() { std::cout << "Complex Constructor 1" << std::endl; } Complex(float re, float im) { std::cout << "Complex Constructor 2" << std::endl; } ~Complex() { std::cout << "Complex Destructor" << std::endl; } }; int main() { Complex a; std::cout << "--------------------------" << std::endl; Complex b(); std::cout << "--------------------------" << std::endl; Complex c(0

C++ Strange constructor behaviour

我的未来我决定 提交于 2019-12-30 21:38:07
问题 Can anybody explain to me the difference between Complex a; and Complex b(); ? #include<iostream> class Complex { public: Complex() { std::cout << "Complex Constructor 1" << std::endl; } Complex(float re, float im) { std::cout << "Complex Constructor 2" << std::endl; } ~Complex() { std::cout << "Complex Destructor" << std::endl; } }; int main() { Complex a; std::cout << "--------------------------" << std::endl; Complex b(); std::cout << "--------------------------" << std::endl; Complex c(0

Without using recursion how can a stack overflow exception be thrown?

故事扮演 提交于 2019-12-30 18:33:08
问题 Without using recursion how can a stack overflow exception be thrown? 回答1: If you call enough methods, a stack overflow can occur anytime. Although, if you get stack overflow errors without using recursion, you may want to rethink how you're doing things. It's just so easy with recursion because in an infinite loop, you call a ton of methods. 回答2: Since no one else has mentioned it: throw new System.StackOverflowException(); You might do this when testing or doing fault-injection. 回答3:

how to check if activity is still in the stack?

孤街浪徒 提交于 2019-12-30 08:58:08
问题 what is the better way to check if the activity is still in the stack in order to call it back ? Intent i = new Intent(getApplicationContext(),MyClass.class); startActivity(i); 回答1: Look at the ActivityManager API To get an instance of the ActivityManager use this code: ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE ); 回答2: I am surprised how unpopular this (kind of) question(s) is. Let me start from the solution first: Since ActivityManager.getRunningTasks is