Skip to content

Commit

Permalink
dijkstra algorithm implementation need to be done properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypatel208 committed Dec 8, 2023
1 parent 68f47fd commit d95608d
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/libraries/KotlinJavaRuntime.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions DSA_JAVA.iml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
41 changes: 41 additions & 0 deletions src/Evaluate142.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import edu.princeton.cs.algs4.StdIn;

import java.util.Stack;

public class Evaluate142 {
public static void main(String[] args) {
Stack<String> ops = new Stack<>();
Stack<Double> vals = new Stack<>();
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("*")) {
ops.push(s);
} else if (s.equals("/")) {
ops.push(s);
} else if (s.equals("sqrt")) {
ops.push(s);
} else if (s.equals(")")) {
String op = ops.pop();
double v = vals.pop();
if (op.equals("+")) {
v = vals.pop() + v;
} else if (op.equals("-")) {
v = vals.pop() - v;
} else if (op.equals("*")) {
v = vals.pop() * v;
} else if (op.equals("/")) {
v = vals.pop() / v;
} else if (op.equals("sqrt")) {
v = Math.sqrt(v);
}
vals.push(v);
}
}
}
}
1 change: 1 addition & 0 deletions src/Flips.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import edu.princeton.cs.algs4.Counter;
import edu.princeton.cs.algs4.Date;
import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.StdRandom;

Expand Down
13 changes: 13 additions & 0 deletions src/MemoryManagement104.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import edu.princeton.cs.algs4.Date;

public class MemoryManagement104 {
public static void main(String[] args) {
Date a = new Date(12, 31, 1999);
System.out.println(a);
Date b = new Date(12,31,2001);
System.out.println(b);
b = a;
System.out.println(a);
System.out.println(b);
}
}
15 changes: 15 additions & 0 deletions src/Reverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

import java.util.Stack;

public class Reverse {
public static void main(String[] args) {
Stack<Integer> stack;
stack = new Stack<>();
while (!StdIn.isEmpty())
stack.push(StdIn.readInt());
while (!stack.isEmpty())
StdOut.println(stack.pop());
}
}
27 changes: 27 additions & 0 deletions src/Stats138.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import edu.princeton.cs.algs4.Bag;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

public class Stats138 {
public static void main(String[] args) {
Bag<Double> numbers = new Bag<>();
while (!StdIn.isEmpty()) {
numbers.add(StdIn.readDouble());
}
int N = numbers.size();

double sum = 0.0;
for (double x : numbers) {
sum += x;
}
double mean = sum/N;

sum = 0.0;
for (double x:numbers){
sum+= (x-mean) * (x-mean);
}
double std = Math.sqrt(sum/(N-1));
StdOut.printf("Mean: %.2f\n", mean);
StdOut.printf("Std dev: %.2f\n", std);
}
}

0 comments on commit d95608d

Please sign in to comment.