Skip to content

Commit 17c45dd

Browse files
committed
commit
1 parent 015050d commit 17c45dd

File tree

56 files changed

+790
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+790
-9
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package hashtable;
2+
3+
import java.util.ArrayList;
4+
5+
public class HashTable {
6+
public void hashInsert(ArrayList<Integer> al,int x){
7+
al.add(hashFunction(x), x);
8+
}
9+
10+
private int hashFunction(int x) {
11+
// TODO Auto-generated method stub
12+
return x*2;
13+
}
14+
public <T> void print(ArrayList<T> al){
15+
for (int i = 0; i < al.size(); i++) {
16+
System.out.println(al.get(i));
17+
}
18+
19+
}
20+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package class1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class StackAndQueue {
7+
8+
static List<Integer> list=new ArrayList<Integer>();
9+
10+
/*// public static void main(String[] args) {
11+
// List<Integer> list=Inital();
12+
// boolean b=stackEmpty(list);
13+
// System.out.println(b);
14+
// list=Push(list,9);
15+
// System.out.println(list);
16+
// list=remove(list,9);
17+
// System.out.println(list);
18+
// }
19+
*/ public StackAndQueue(List< Integer> list){
20+
this.list=list;
21+
System.out.println("hello github");
22+
23+
}
24+
public static List<Integer> Inital(){
25+
list.add(3);
26+
list.add(5);
27+
list.add(9);
28+
return list;
29+
}
30+
public static List Push(List list,int a){
31+
list.add(a);
32+
return list;
33+
}
34+
public static List remove(List list,int a){
35+
list.remove(list.size()-1);
36+
return list;
37+
}
38+
public static boolean stackEmpty(List< Integer> list){
39+
List list1=new ArrayList<>();
40+
System.out.println(list);
41+
System.out.println(list.hashCode());
42+
System.out.println(list1.hashCode());
43+
if (list==null)
44+
return true;
45+
else
46+
return false;
47+
}
48+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package class1;
2+
3+
import class1.LinkedList.Node;
4+
5+
/**
6+
* 双向链表
7+
* @author liyafei
8+
*
9+
* @param <T>
10+
*/
11+
public class DoubleDirectionLinkedList <T>{
12+
doubleNode<T> head,current,trail=null;
13+
14+
class doubleNode<T>{
15+
doubleNode<T> pre;
16+
doubleNode<T> next;
17+
T key;
18+
}
19+
public void delete(doubleNode<T> node,T key){ //删除
20+
21+
while (node.key !=key){
22+
node=node.next;
23+
}
24+
if(node.pre!=null){
25+
node.pre.next=node.next;
26+
}else{
27+
head=node.next;
28+
}
29+
if(node.next!=null){
30+
node.next.pre=node.pre;
31+
}
32+
// if (node.pre==null){
33+
// if(node.next==null){
34+
// head=null;
35+
// }else{
36+
// head=node.next;
37+
// head.next=node.next.next;
38+
// }
39+
// }else{
40+
// if(node.next==null){
41+
// trail=node.pre;
42+
// trail.pre=node.pre.pre;
43+
// }else{
44+
/* doubleNode<T> tem=node.pre;
45+
doubleNode<T> tem1=node.next;
46+
tem.next=node.next;
47+
tem1.pre=tem;*/
48+
// node.pre=tem;
49+
// node.next=tem1;
50+
51+
// }
52+
//}
53+
54+
}
55+
56+
public void insert(T key){ //插入一个节点,创建一个树结构是插入很多个的集合。
57+
doubleNode<T> newNode=new doubleNode<T>();
58+
newNode.key=key;
59+
newNode.next=null;
60+
if(head==null){
61+
head=newNode;
62+
head.pre=null;
63+
trail=newNode;
64+
}else{
65+
trail.next=newNode;
66+
newNode.pre=trail;
67+
trail=newNode;
68+
}
69+
}
70+
public void print(doubleNode<T> node){ //给一个头节点,打印链表
71+
while(node!=null){
72+
System.out.println(node.key);
73+
node=node.next; //逆向打印双向链表
74+
}
75+
}
76+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package hashtable;
2+
3+
import java.util.ArrayList;
4+
5+
import org.omg.PortableInterceptor.INACTIVE;
6+
7+
public class TestClass {
8+
public static HashTable ht=new HashTable();
9+
public static void main(String[] args) {
10+
ArrayList<Integer> al=new ArrayList<>();
11+
;
12+
ht.hashInsert(al, 5);
13+
ht.hashInsert(al, 2);
14+
ht.hashInsert(al, 6);
15+
ht.hashInsert(al, 7);
16+
ht.print(al);
17+
}
18+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package binarytree;
2+
3+
public class BinaryTree<T extends Comparable<T>> {
4+
Node<T> root = null;
5+
6+
public class Node<T extends Comparable<T>> {
7+
Node leftChild;
8+
Node rightChild;
9+
Node parent;
10+
T key;
11+
}
12+
13+
public void print(Node node) {
14+
System.out.println(node.leftChild.key);
15+
}
16+
17+
public void delete(T key){
18+
Node temNode=new Node();
19+
Node newNode=new Node();
20+
newNode.key=key;
21+
temNode=root;
22+
while(newNode.key!=temNode.key){
23+
if(temNode.key.compareTo(newNode.key)<0){
24+
temNode=temNode.rightChild;
25+
}else
26+
temNode=temNode.leftChild;
27+
}
28+
if(temNode.leftChild==null){
29+
transplant(temNode,temNode.rightChild);
30+
}else if(temNode.rightChild==null){
31+
transplant(temNode, temNode.leftChild);
32+
}
33+
else{
34+
Node minRight=minimum(temNode.rightChild);
35+
if(minRight.parent!=temNode){
36+
transplant(minRight, minRight.rightChild);
37+
minRight.rightChild=temNode.rightChild;
38+
minRight.rightChild.parent=minRight;
39+
}
40+
transplant(temNode, minRight);
41+
minRight.leftChild=temNode.leftChild;
42+
minRight.leftChild.parent=minRight;
43+
}
44+
}
45+
// public void delete(T key){
46+
//// Node newNode=new Node();
47+
//// newNode.key=key;
48+
//// Node tem=root;
49+
////
50+
////
51+
//// if (newNode.key.compareTo(tem.key) < 0) {
52+
//// tem = tem.leftChild;
53+
//// } else {
54+
//// tem = tem.rightChild;
55+
//// }
56+
//// }
57+
//tem是最后和给定值相等的节点。
58+
// if (tem.rightChild==null)
59+
// transplant();
60+
// else if tem.rightChild==null
61+
// transplant();
62+
// else y=treeMinimum(tem.rightChild) //右孩子中的最小值。
63+
// if (y.p!=z)
64+
// transplant(t,y,y.right)
65+
// y.right=z.right
66+
// y.right.p=y
67+
// Transplant(T,z,y)
68+
// y.left.p=z.left
69+
// }
70+
//
71+
// private void transplant() {
72+
// // TODO Auto-generated method stub
73+
//
74+
// }
75+
76+
private Node minimum(Node rightChild) {
77+
// TODO Auto-generated method stub
78+
while(rightChild.leftChild!=null){
79+
rightChild=rightChild.leftChild;
80+
}
81+
return rightChild;
82+
}
83+
84+
private void transplant(Node temNode, Node rightChild) {
85+
// TODO Auto-generated method stub
86+
if(temNode.parent==null){
87+
root=rightChild;
88+
}else if(temNode.key.compareTo(temNode.parent.leftChild.key)==0){
89+
temNode.parent.leftChild=rightChild;
90+
}else{
91+
temNode.parent.rightChild=temNode;
92+
}
93+
if(rightChild!=null){
94+
rightChild.parent=temNode.parent;
95+
}
96+
}
97+
98+
99+
100+
101+
102+
103+
public void insert(T key) { // 向二叉树中插入
104+
Node newNode = new Node();
105+
newNode.key = key;
106+
Node tem = root;
107+
Node p = null;
108+
while (tem != null) {
109+
p = tem;
110+
if (newNode.key.compareTo(tem.key) < 0) {
111+
tem = tem.leftChild;
112+
} else {
113+
tem = tem.rightChild;
114+
}
115+
}
116+
newNode.parent = p;
117+
118+
if (p == null) { //二叉树为空时。
119+
root = newNode;
120+
121+
} else if ((newNode.key).compareTo(p.key) < 0) {
122+
123+
p.leftChild = newNode;
124+
} else {
125+
p.rightChild = newNode;
126+
}
127+
}
128+
129+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package hashtable;
2+
3+
import java.util.ArrayList;
4+
5+
/**
6+
* 哈希表
7+
* @author liyafei
8+
*
9+
*/
10+
public class HashTable {
11+
public void hashInsert(ArrayList<Integer> al,int x){
12+
al.add(hashFunction(x), x);
13+
}
14+
15+
/**
16+
* 哈希函数
17+
* @param x 输入参数
18+
* @return 哈希函数
19+
*/
20+
private int hashFunction(int x) {
21+
// TODO Auto-generated method stub
22+
return x*2;
23+
}
24+
25+
public <T> void print(ArrayList<T> al){
26+
for (int i = 0; i < al.size(); i++) {
27+
System.out.println(al.get(i));
28+
}
29+
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package binarytree;
2+
3+
import binarytree.BinaryTree.Node;
4+
5+
public class TestClass {
6+
public static void main(String[] args) {
7+
BinaryTree<Integer> bt=new BinaryTree<>();
8+
bt.insert(5);
9+
bt.insert(9);
10+
bt.insert(6);
11+
bt.insert(3);
12+
bt.insert(5);
13+
bt.insert(9);
14+
bt.insert(6);
15+
bt.insert(2);
16+
Node node=bt.root;
17+
bt.print(node);
18+
19+
bt.delete(3);
20+
bt.print(node);
21+
}
22+
}

0 commit comments

Comments
 (0)