Check links below:
- Format My Source Code for Blogging
- Blogger Code Formatting
- SyntaxHighlighter
- Blogger Source Code Formatter
- Formatting Source Code For Blog Posts
- Type of Style: Style Classes
- Whitespace Options:
Java class Node
package source;
import java.util.LinkedList;
import java.util.List;
public class Node {
public List<Node> nodes = new LinkedList<Node>();
public int data;
public boolean isMarked;
public Node(int data) {
this.data = data;
isMarked = false;
}
public void add(Node node) {
nodes.add(node);
}
}
Java class Graph
package source;
import java.util.LinkedList;
import java.util.Queue;
public class Graph {
public Node root;
public Graph(Node root) {
this.root = root;
}
public void dfs() {
dfs(root);
System.out.println();
}
private void dfs(Node node) {
if (node == null)
return;
System.out.print(node.data+" ");
for(Node n: node.nodes) {
dfs(n);
}
}
public void bfs() {
Queue<Node> queue = new LinkedList<Node>();
queue.add(root);
bfs(queue);
System.out.println();
}
private void bfs(Queue<Node> queue) {
while (!queue.isEmpty()) {
Node node = queue.remove();
System.out.print(node.data+" ");
for(Node n: node.nodes) {
queue.add(n);
}
}
}
}
Other useful formatter is c# code format
No comments:
Post a Comment