infix postfix
package dyndaten;
/ **
The evaluation of expressions is often called the . postfix. Examples of the conversion of a
infix expression (two-digit operators are standing between the operands) in a Postfix expression
(operators are always on the right of the operand, and to get along entirely without braces, in the evaluation of
left refers to the right, an operator on the immediate left of him resulting arguments) are: #
Infix -> Postfix
# 1 + 2 - 3 * (4 + 5) # -> # 1 2 3 4 5 + + * - 1 ^ 2
- 3 * 4 # -> # 1 2 ^ 3 4 * -
(1 + 2) * 3 + (4 ^ (5 - 6)) # -> # 1 2 3 4 5 6 + - ^ +
1 + 2 + 3 / 4 + 5 + 6 * (7 + 8) # -> # Allows 1 2 3 4 + / + 5 + 6 + 7 8 * +
The infix expression, the operators of exponentiation (^), multiplication (*), division (/) Addition (+) and subtraction (-)
and any nested brackets included. The operators are those that are customary in the execution based on priority rules.
Notes:
Note the order of operands in infix and postfix expression. What do you notice?
use in the implementation of a stack to the cellars of the operators, and parentheses.
Note the different priorities of the operators.
Enter a Java program in which an arbitrarily parenthesized infix expression as a row of a keyboard input and output as a Postfix reads
expression.
java.io.IOException * / import
;
public class into post
theStack {private stack;
private String input;
private String output = "";
into public post (String in) {
input = in ;
stack int size = input.length ();
theStack = new stack (stack size);}
doTrans public String () {
for (int j = 0, j \u0026lt;input.length () j + +)
{char ch =
input.charAt (j);
switch (ch)
{
case '+':
case '-':
gotOper(ch, 1);
break; // (precedence 1)
case '*': // it's * or /
case '/':
gotOper(ch, 2); // go pop operators
break; // (precedence 2)
case '(': // it's a left paren
theStack.push(ch); // push it
break;
case ')': // it's a right paren
gotParen(ch); // go pop operators
break;
default: // must be an operand
output = output + ch; // write it to output
break;
}
}
while (!theStack.isEmpty())
{
output = output + theStack.pop();
}
//System.out.println(output);
return output; // return postfix
}
public void gotOper(char opThis, int prec1)
{
while (!theStack.isEmpty())
{
char opTop = theStack.pop();
if (opTop == '(')
{
theStack.push(opTop);
break;}
/ / it's an operator
else {/ / int precedence of new op
prec2;
if (opTop == '+'
}
theStack.push(opThis);
}
public void gotParen(char ch)
{
while (!theStack.isEmpty())
{
char chx = theStack.pop();
if (chx == '(')
break;
else
output = output + chx;
}
}
public static void main(String[] args) throws IOException
{
String input = "1 + 2 - 3 * (4 + 5)";
String output;
InToPost theTrans = new InToPost(input);
output = theTrans.doTrans();
System.out.println("Infix is " + input + '\n');
System.out.println("Postfix is " + output + '\n');
}
class Stack
{
private int maxSize;
private char[] stackArray;
private int top;
public Stack(int max)
{
maxSize = max;
stackArray = new char[maxSize];
top = -1;
}
public void push(char j)
{
stackArray[++top] = j;
}
public char pop()
{
return stackArray[top--];
}
public char peek()
{
return stackArray[top];
}
public boolean isEmpty()
{
return (top == -1);
}
}
}
Thursday, December 28, 2006
Monday, December 18, 2006
Plato Dvd Ripper Professional Get Free License
mcCarthy
public class McCarthy
{
int f(int n)
{
if (n > 100)
{
return n - 10;
}
else
{
return f(f(n + 11));
} // if
} // f
} // McCarthy
class McCarthyProgram
{
public static void main(String[] args)
{
McCarthy mc = new McCarthy();
int n = 102;
System.out.println(mc.f(n));
} // main
} // McCarthyProgram
public class McCarthy
{
int f(int n)
{
if (n > 100)
{
return n - 10;
}
else
{
return f(f(n + 11));
} // if
} // f
} // McCarthy
class McCarthyProgram
{
public static void main(String[] args)
{
McCarthy mc = new McCarthy();
int n = 102;
System.out.println(mc.f(n));
} // main
} // McCarthyProgram
Is Waxing Okay For A 16 Year Old Male
array and sort
package testwiese;
/**
* Summary description for Program
*/
public class Arra
{
public static void gibFeld(int[] feld)
{
for (int e = 0; e < feld.length; e++)
{
int h=feld[e];
System.out.print(h+",");
}
}
public static void wasTueIch(int[] feld)
{
int o=0;
int b = 0;
int i, j;
int temp;
int n = feld.length;
int distanz = n / 2;
while (distanz > 0)
{
for (i = distanz; i < feld.length; i++)
{
j = i - distanz;
while (j >= 0)
{
if (feld[j] > feld[j + distanz])
{
temp = feld[j];
feld[j] = feld[j + distanz];
feld[j + distanz] = temp;
j = j - distanz;
} else {
j = -1;}
/ / inside
b + +;
System.out.println ();
System.out.println ("inside:" + b + "->") ;
gibFeld (field);}
}
distance = distance / 2;
/ / outside
o + +;
System.out.println ();
System.out.println ("###### ####### --- the outside: "+ o);
gibFeld (field);
System.out.println ();}
}}
public class Program {
public static void main (String [] args) {
int nums [] = {56,22,79,27,9 , 30,61,4,69,38,52,89,23,17,68};
Arra.wasTueIch (nums);}
package testwiese;
/**
* Summary description for Program
*/
public class Arra
{
public static void gibFeld(int[] feld)
{
for (int e = 0; e < feld.length; e++)
{
int h=feld[e];
System.out.print(h+",");
}
}
public static void wasTueIch(int[] feld)
{
int o=0;
int b = 0;
int i, j;
int temp;
int n = feld.length;
int distanz = n / 2;
while (distanz > 0)
{
for (i = distanz; i < feld.length; i++)
{
j = i - distanz;
while (j >= 0)
{
if (feld[j] > feld[j + distanz])
{
temp = feld[j];
feld[j] = feld[j + distanz];
feld[j + distanz] = temp;
j = j - distanz;
} else {
j = -1;}
/ / inside
b + +;
System.out.println ();
System.out.println ("inside:" + b + "->") ;
gibFeld (field);}
}
distance = distance / 2;
/ / outside
o + +;
System.out.println ();
System.out.println ("###### ####### --- the outside: "+ o);
gibFeld (field);
System.out.println ();}
}}
public class Program {
public static void main (String [] args) {
int nums [] = {56,22,79,27,9 , 30,61,4,69,38,52,89,23,17,68};
Arra.wasTueIch (nums);}
Thursday, November 16, 2006
Mac Emulator Pokemon Pearl
751-1
} / / An object of class car keeps track of the current
/ / Mileage and the existing fuel supply.
public class Car {
/ / mileage, according to speedometer
private int kmStand;
/ / consumption to 100 km double
private consumption;
/ / volume of the tank, fits more fuel not fit tank volume
private double;
/ / in the tank fuel
private double fuel supply;
/ / General Constructor: Attributes kmStand, consumption,
/ tank volume / and fuel storage initialize
/ / The fuel supply may be not greater than the tank volume.
public Car (int km, double bridged, double volume, double last)
{
kmStand = km;
consumption = bridged;
tank volume = volume;
if (storage volume>)
reserve = volume;
fuel storage = storage;
}
/ / attribute values of the oject car
public String toString () return
{
("mileage" + kmStand + "Usage:" + consumption + "Tank:"
tank volume + + "set: "Fuel supply +);
}
/ / info: Is the current mileage and fuel tank capacity of
public void info ()
{
System.out.println (" kmStand: "+ kmStand +
" fuel supply " + fuel storage);}
/ / drive: We drive the specified number of miles.
/ / The mileage will be adjusted and the fuel supply
/ / reduced accordingly. We can of course only
/ / so far are, as the fuel supply limitations in the tank.
public void run (int km) {
System.out.println ("go (" + km + ")");
/ / here is an explicit cast double -> int int
necessary current range = ( current range
if (km> current range)
km =, int) (fuel supply / consumption * 100) =
kmStand kmStand + km;
fuel supply = Fuel supply - km / 100 * consumption;
System.out.println (km + km on the clock. ");}
refuel / /: This argument specifies liter,
/ / how much fuel should be recharged .
/ / Note: the volume of the tank is limited!
/ / We are allowed to fill up too much fuel.
public void fill (double liter)
{
System.out.println ("fill up (" + l + ")");
if (fuel storage + tank volume liter>)
liter tank volume = - fuel storage;
Fuel tank capacity = fuel supply + Liters;
System.out.println (liters + "liter tank.");}
} / / public class Bus extends Omnibus
car
{/ / Number of seats Number of seats
private int;
/ / General Constructor: kmStand attributes, consumption,
/ / tank volume, fuel capacity and number of seats initialize
public bus (int km, double bridged, double volume, double reservoir, int seats)
{
/ / constructor of the superclass call
super ( km, bridged volume, store);
number of seats = seats;}
/ / Attribute values of the oject Omnibus
public String toString ()
{return
(super.toString () + "seats" + number of seats);
}
}
public class Car
{
/ / Main program to test the Car class
public static void main (String [] args) {
Goggomobil car = new Car (0, 5.0, 50.0, 30.0);
einBus bus = new Bus (0, 5.0, 50.0, 30.0, 12);
System.out.println (Goggomobil);
System.out.println (einBus);
goggoMobil.info ();
goggoMobil.fahren (300);
goggoMobil.info ();
goggoMobil.tanken (45.0); goggoMobil.fahren
(800);
goggoMobil.info () goggoMobil.fahren
(700);
goggoMobil.info ()
Goggomobil. info ();}
} / / An object of class car keeps track of the current
/ / Mileage and the existing fuel supply.
public class Car {
/ / mileage, according to speedometer
private int kmStand;
/ / consumption to 100 km double
private consumption;
/ / volume of the tank, fits more fuel not fit tank volume
private double;
/ / in the tank fuel
private double fuel supply;
/ / General Constructor: Attributes kmStand, consumption,
/ tank volume / and fuel storage initialize
/ / The fuel supply may be not greater than the tank volume.
public Car (int km, double bridged, double volume, double last)
{
kmStand = km;
consumption = bridged;
tank volume = volume;
if (storage volume>)
reserve = volume;
fuel storage = storage;
}
/ / attribute values of the oject car
public String toString () return
{
("mileage" + kmStand + "Usage:" + consumption + "Tank:"
tank volume + + "set: "Fuel supply +);
}
/ / info: Is the current mileage and fuel tank capacity of
public void info ()
{
System.out.println (" kmStand: "+ kmStand +
" fuel supply " + fuel storage);}
/ / drive: We drive the specified number of miles.
/ / The mileage will be adjusted and the fuel supply
/ / reduced accordingly. We can of course only
/ / so far are, as the fuel supply limitations in the tank.
public void run (int km) {
System.out.println ("go (" + km + ")");
/ / here is an explicit cast double -> int int
necessary current range = ( current range
if (km> current range)
km =, int) (fuel supply / consumption * 100) =
kmStand kmStand + km;
fuel supply = Fuel supply - km / 100 * consumption;
System.out.println (km + km on the clock. ");}
refuel / /: This argument specifies liter,
/ / how much fuel should be recharged .
/ / Note: the volume of the tank is limited!
/ / We are allowed to fill up too much fuel.
public void fill (double liter)
{
System.out.println ("fill up (" + l + ")");
if (fuel storage + tank volume liter>)
liter tank volume = - fuel storage;
Fuel tank capacity = fuel supply + Liters;
System.out.println (liters + "liter tank.");}
} / / public class Bus extends Omnibus
car
{/ / Number of seats Number of seats
private int;
/ / General Constructor: kmStand attributes, consumption,
/ / tank volume, fuel capacity and number of seats initialize
public bus (int km, double bridged, double volume, double reservoir, int seats)
{
/ / constructor of the superclass call
super ( km, bridged volume, store);
number of seats = seats;}
/ / Attribute values of the oject Omnibus
public String toString ()
{return
(super.toString () + "seats" + number of seats);
}
}
public class Car
{
/ / Main program to test the Car class
public static void main (String [] args) {
Goggomobil car = new Car (0, 5.0, 50.0, 30.0);
einBus bus = new Bus (0, 5.0, 50.0, 30.0, 12);
System.out.println (Goggomobil);
System.out.println (einBus);
goggoMobil.info ();
goggoMobil.fahren (300);
goggoMobil.info ();
goggoMobil.tanken (45.0); goggoMobil.fahren
(800);
goggoMobil.info () goggoMobil.fahren
(700);
goggoMobil.info ()
Goggomobil. info ();}
Monday, November 6, 2006
How To Make Fire Bricks
fmt @ 2006-11-06T20: 23:00
} public class Program {
public static void main (String args []) {
zahlenBis int = 100;
/ / adjust numbers: from 2 .. and # of . determine the fields
zahlenVon int = 2;
int = anzFelder zahlenBis - 1;
/ / arrays
int [] numbers = new int field [anzFelder];
boolean [] number info = new boolean [anzFelder];
/ / All figures write
for (int i = 0; i \u0026lt;zahlenFeld.length; i + +, zahlenVon + +)
{
[i] number field = zahlenVon;
}
/ / values for all numbers to true
for (int i = 0; i \u0026lt;zahlenInfo.length; i + +) {
number info [i] = true;}
/ / prime loop
for ( int i = 0; i \u0026lt;zahlenFeld.length; i + +) {
/ / is Prime?
if (number info [i] == true) {
for (int j = i +1, j \u0026lt;zahlenFeld.length j + +) {
if (number info [j] == true & (number field [j] % number of field [i]) == 0) {
number info [j] = false;}
}}
} / / output the primes
for (int i = 0; i \u0026lt;zahlenFeld.length ; i + +) {
if (number info [i] == true) {
System.out.println (number field [i] + "");}
}
}}
} public class Program {
public static void main (String args []) {
zahlenBis int = 100;
/ / adjust numbers: from 2 .. and # of . determine the fields
zahlenVon int = 2;
int = anzFelder zahlenBis - 1;
/ / arrays
int [] numbers = new int field [anzFelder];
boolean [] number info = new boolean [anzFelder];
/ / All figures write
for (int i = 0; i \u0026lt;zahlenFeld.length; i + +, zahlenVon + +)
{
[i] number field = zahlenVon;
}
/ / values for all numbers to true
for (int i = 0; i \u0026lt;zahlenInfo.length; i + +) {
number info [i] = true;}
/ / prime loop
for ( int i = 0; i \u0026lt;zahlenFeld.length; i + +) {
/ / is Prime?
if (number info [i] == true) {
for (int j = i +1, j \u0026lt;zahlenFeld.length j + +) {
if (number info [j] == true & (number field [j] % number of field [i]) == 0) {
number info [j] = false;}
}}
} / / output the primes
for (int i = 0; i \u0026lt;zahlenFeld.length ; i + +) {
if (number info [i] == true) {
System.out.println (number field [i] + "");}
}
}}
Saturday, October 21, 2006
Facial Hair Generator
fmt @ 2006-10-21T23: 13:00
http://fastwindows.blogspot.com/2006/09/faster-windows-xp-heres- how.html
http://fastwindows.blogspot.com/2006/09/faster-windows-xp-heres- how.html
Subscribe to:
Posts (Atom)