Why won't Perl let me chain a postfix loop from a postfix comparison?
By : user1272262
Date : March 29 2020, 07:55 AM
wish helps you You can only have one postfix operation per statement. But you can do what you want (sorta) by using a do block, e.g. code :
do { $foo++ if $condition } for ( 1..10 );
for( 1..10 ) { $foo++ if $condition }
|
INSERT array into mysql table (only zeros as result)
By : Joao Luis Orgal
Date : March 29 2020, 07:55 AM
around this issue Inside each item in your array $ar there is another array. So your query should be: code :
$sql = " INSERT INTO table(yo) VALUES('".$ar[$i]['ciao']."') " ;
|
Converting from Infix to Postfix and evaluating Postfix notation
By : WarpSpeed
Date : March 29 2020, 07:55 AM
it fixes the issue One problem is your are storing values in s as a char with storage of 1 byte per element and then attempt to push integers into s with: code :
pushit (int ele) { /* Function for PUSH operation */
s[++top] = ele;
}
op2=popit();
op1=popit();
int popit(){ /* Function for POP operation */
return(s[top--]);
}
popit.c:8:1: warning: return type defaults to ‘int’
popit.c:32:1: warning: return type defaults to ‘int’
popit.c:41:1: warning: return type defaults to ‘int’
|
PostFix Evaluation Result Error
By : LineByLine
Date : March 29 2020, 07:55 AM
To fix this issue I dont have a computer at hand, only an old school paper and pen, my phone and some knowledge about the shunting-yard algorithm. I think your error is this (only tested on paper): code :
evaluateStack.push(evaluateStack.pop() + evaluateStack.pop());
//Don't change pop order here!
int righthand = evaluateStack.pop();
int lefthand = evaluateStack.pop();
evaluateStack.push(lefthand + righthand);
public static int postFixEvaluation(int[] numValues, String postfix){
Stack<Integer> evaluateStack = new Stack<Integer>();
char[] chars = postfix.toCharArray();
int length = chars.length;
int currentNumValue =0;
int currentLocation =0;
for (int i = 0; i < length; i++){
char currentChar = chars[i];
//checks to see if character is a letter
if (Character.isLetter(currentChar)){
//replace all letters with values
currentLocation = charToNum(currentChar);//this retrieves the location of specific letter
currentNumValue = (numValues[currentLocation]);//retrieves the value of that location
evaluateStack.push(currentNumValue);//get the number value of that variable and push it on stack
System.out.println(Arrays.toString(evaluateStack.toArray()));//prints out stack elements
}
//checks if character is an operator
if (isOperator(currentChar)){
int righthand = evaluateStack.pop();
int lefthand = evaluateStack.pop();
switch (currentChar){
//switches evaluation according to operator
case '+': evaluateStack.push(lefthand + righthand); break;
case '*': evaluateStack.push(lefthand * righthand); break;
case '-': evaluateStack.push(lefthand - righthand); break;
case '/': evaluateStack.push(lefthand / righthand); break;
}
}
}
if (!evaluateStack.isEmpty()){ //as long as the stack is not empty
return evaluateStack.pop();//returns the result
} else {
return 0; //if it is empty returns zero
}
}
|
Convert a Postfix expression to infix and calculate the postfix and give the answer
By : jdog
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have been working on this program to take in a postfix expression, calculate and print out its answer, and also convert it to infix expression. I have gotten the calculation part of it to work. For instance, if I enter 2 2 +(accounting for the spacing) it gives me 4. However, for the infix part of it it prints out 2+. I then tried it just doing it without any spacing. I put in 22+. The postfix did not work, but the infix printed out properly. So I am not sure how to fix this part of it. Here is my code. code :
if (isOperator(ch))
{
TreeNode rightNode = nodes.pop();
TreeNode leftNode = nodes.pop();
nodes.push(new TreeNode(leftNode, ch, rightNode));
}
else
{
nodes.add(new TreeNode(null, ch, null));
}
if (isOperator(ch))
{
TreeNode rightNode = nodes.pop();
TreeNode leftNode = nodes.pop();
nodes.push(new TreeNode(leftNode, ch, rightNode));
}
else if (!Character.isWhitespace(ch))
{
nodes.add(new TreeNode(null, ch, null));
}
|