-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDijkstra algorithm
More file actions
30 lines (28 loc) · 879 Bytes
/
Dijkstra algorithm
File metadata and controls
30 lines (28 loc) · 879 Bytes
1
// Dijkastra algorithm two-stackvalue: push onto the value stackoperator: push onto the operator stackleft parenthesis: ignoreright parenthesis: pop operator and two values; push the result of applying that operator to those values onto the operand stackpublic class Evaluate { public static void main (String [] args) { Stack<String> ops = new Stack <String> (); Stack<Double> vals = nerw Stack <Double>(); while (!StdIn. isEmpty()){ String s = StdIn.readString (); if (s.equals(Ò(Ò)) ; else if (s.equals(Ò+Ó)) ops.push (s); else if (s.equals(Ò*Ó)) ops.push (s); else if (s.equals(Ò)Ó)) { String op = ops.pop(); if (op.equals(Ò+Ó)) vals.push(vals.pop() + vals.pop ()); else if (op.equals(Ò*Ó)) vals.push(vals.pop() * vals.pop()); } else vals.push(Double.parseDouble(s)); } StdOut.println(vals.pop)); }}