G song recruit school Java interview the interviewer Qinshou

G song recruit school Java interview the interviewer Qinshou

 

List
Array

 

List

 

Queues, stacks

 

Tree
Binary Tree

 

Search tree

 

Heap / priority queue

 

Stack / queue / priority queue
push (1); push (3 ); push (2); pop (); pop (); pop ();
Stack: 2; 3; 1
queue: 1; 3; 2
priority queue: . 1; 2;. 3
the Map <K, V> / the Set <K>
the HashMap / HashSet → K.hashCode ()

 

TreeMap/TreeSet → K implements Comparable

 

FIG
undirected graph
digraph
directed acyclic graph 

 

The algorithm of FIG
depth-first traversal
breadth first traversal
topological sort
Shortest / Minimum Spanning Tree

 

6--15 tree
face questions about the tree

is easy to understand difficult
comprehensive and strong
binary tree traversal
sequence traversal
preorder
preorder traversal after
traverse the level
order traversal how
to traverse the tree roots

 

Then preorder traversal left subtree

 

Then order traverse the front right subtree

 

 

 

// 手动创建一个二叉树
public class TreeCreator {
public TreeNode createSampleTree() {
TreeNode root = new TreeNode('A');
root.setLeft(new TreeNode('B'));
root.getLeft().setLeft(new TreeNode('D'));
root.getLeft().setRight(new TreeNode('E'));
root.getLeft().getRight().setLeft(new TreeNode('G'));
root.setRight(new TreeNode('C'));
root.getRight().setRight(new TreeNode('F'));
return root;
}
}


public class TreeTraversal {

//前序遍历
public void preOrder(TreeNode root) {
if (root == null) {
return;
}
System.out.print(root.getValue());
preOrder(root.getLeft());
preOrder(root.getRight());
}

//中序遍历
public void inOrder(TreeNode root) {
if (root == null) {
return;
}
inOrder(root.getLeft());
System.out.print(root.getValue());
inOrder(root.getRight());
}

//后序遍历
public void postOrder(TreeNode root) {
if (root == null) {
return;
}
postOrder(root.getLeft());
postOrder(root.getRight());
System.out.print(root.getValue());
}
}
public static void main(String[] args) {
TreeCreator creator = new TreeCreator();
TreeTraversal traversal = new TreeTraversal();

System.out.println("Sample tree traversal");
System.out.println("=====");
TreeNode sampleTree = creator.createSampleTree();
traversal.preOrder(sampleTree);
System.out.println();
traversal.inOrder(sampleTree);
System.out.println();
traversal.postOrder(sampleTree);
System.out.println();

System.out.println("=====");
}
Sample tree traversal
=====
ABDEGCF
DBGEACF
DGEBFCA
=====

 

Guess you like

Origin www.cnblogs.com/itpy/p/11825981.html