Skip to content

General implementation cleanup #849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions contents/huffman_encoding/code/java/huffman.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import java.util.*;

class Huffman {
public static void main(String[] args) {
HuffmanTree huffmanTree = new HuffmanTree("bibbity_bobbity");
huffmanTree.createTree();
String encoded = huffmanTree.encode();
System.out.println("Encoded String: " + encoded);
System.out.println("Decoded String: " + huffmanTree.decode(encoded));
}
}

class TreeNode {
String letter = "";
int frequency = 0;
Expand Down Expand Up @@ -101,13 +111,3 @@ public String decode(String encoded) {
return decoded.toString();
}
}

class Huffman {
public static void main(String[] args) {
HuffmanTree huffmanTree = new HuffmanTree("bibbity_bobbity");
huffmanTree.createTree();
String encoded = huffmanTree.encode();
System.out.println("Encoded String: " + encoded);
System.out.println("Decoded String: " + huffmanTree.decode(encoded));
}
}
5 changes: 1 addition & 4 deletions contents/monte_carlo_integration/code/c++/monte_carlo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ double monte_carlo_pi(unsigned samples) {
int main() {
unsigned samples;

std::cout << "Enter samples to use: ";
std::cin >> samples;

double pi_estimate = monte_carlo_pi(samples);
double pi_estimate = monte_carlo_pi(10000000);
std::cout << "Pi = " << pi_estimate << '\n';
std::cout << "Percent error is: " << 100 * std::abs(pi_estimate - PI) / PI << " %\n";
}
31 changes: 0 additions & 31 deletions contents/tree_traversal/code/java/MainClass.java

This file was deleted.

30 changes: 30 additions & 0 deletions contents/tree_traversal/code/java/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,34 @@ public int compareTo(Node other) {
return Integer.compare(this.id, other.id);
}
}

public static void main(String[] args) {
System.out.println("Creating Tree");
Tree tree = new Tree(3, 3);

System.out.println("Using recursive DFS :");
tree.dfsRecursive();

System.out.println("Using stack-based DFS :");
tree.dfsStack();

System.out.println("Using queue-based BFS :");
tree.bfsQueue();

System.out.println("Using post-order recursive DFS :");
tree.dfsRecursivePostOrder();


// Uncommenting the following 2 lines will result in an exception thrown because at least one Node of the Tree has more than 2 children and therefor a DFSRecursiveInorderBinary doesn't work.
System.out.println("Using in-order binary recursive DFS : (fail)");
tree.dfsRecursiveInOrderBinary();

tree = new Tree(3, 2);
System.out.println("Using in-order binary recursive DFS : (succeed)");
tree.dfsRecursiveInOrderBinary();


System.out.println("");
}

}
2 changes: 0 additions & 2 deletions contents/tree_traversal/tree_traversal.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ Here is a video describing tree traversal:
{% sample lang="java" %}
##### Tree.java
[import, lang:"java"](code/java/Tree.java)
##### MainClass.java
[import, lang:"java"](code/java/MainClass.java)
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
Expand Down
12 changes: 12 additions & 0 deletions contents/verlet_integration/code/java/Verlet.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
public class Verlet {

private static class VerletValues {
public double time;
public double vel;

public VerletValues(double time, double vel) {
this.time = time;
this.vel = vel;
}
}


static double verlet(double pos, double acc, double dt) {

// Note that we are using a temp variable for the previous position
Expand Down
9 changes: 0 additions & 9 deletions contents/verlet_integration/code/java/VerletValues.java

This file was deleted.

7 changes: 3 additions & 4 deletions contents/verlet_integration/verlet_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Here is what it looks like in code:
{% sample lang="c" %}
[import:3-14, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
[import:2-17, lang:"java"](code/java/Verlet.java)
[import:14-29, lang:"java"](code/java/Verlet.java)
{% sample lang="py" %}
[import:1-10, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
Expand Down Expand Up @@ -95,7 +95,7 @@ However, the error for this is $$\mathcal{O}(\Delta t)$$, which is quite poor, b
{% sample lang="c" %}
[import:16-31, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
[import:19-37, lang:"java"](code/java/Verlet.java)
[import:31-49, lang:"java"](code/java/Verlet.java)
{% sample lang="py" %}
[import:12-23, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
Expand Down Expand Up @@ -167,7 +167,7 @@ Here is the velocity Verlet method in code:
{% sample lang="c" %}
[import:33-43, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
[import:39-51, lang:"java"](code/java/Verlet.java)
[import:51-63, lang:"java"](code/java/Verlet.java)
{% sample lang="py" %}
[import:25-34, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
Expand Down Expand Up @@ -225,7 +225,6 @@ Both of these methods work simply by iterating timestep-by-timestep and can be w
{% sample lang="c" %}
[import, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
[import, lang:"java"](code/java/VerletValues.java)
[import, lang:"java"](code/java/Verlet.java)
{% sample lang="py" %}
[import, lang:"python"](code/python/verlet.py)
Expand Down