Skip to content

Commit 6c89262

Browse files
authored
Merge pull request onlyliuxin#1 from honokaBiu/master
更新版本库,提交week2
2 parents 51449dd + d79fb4a commit 6c89262

File tree

110 files changed

+4204
-502
lines changed

Some content is hidden

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

110 files changed

+4204
-502
lines changed

.project

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>coding2017</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
public class ArrayList<T> implements List<T> {
2+
//private fields
3+
private int size = 0;
4+
private Object[] elementData = new Object[100];
5+
//check if list is empty
6+
public boolean isEmpty() {
7+
return size == 0;
8+
}
9+
10+
public void add(Object o){
11+
elementData[size++] = o;
12+
}
13+
public void add(int index, T o){
14+
/* Not familiar with array copy, copied from GitMori */
15+
System.arraycopy(elementData, index, elementData,
16+
index + 1, size-index);
17+
elementData[index] = o;
18+
size++;
19+
}
20+
21+
public T get(int index){
22+
return (T) elementData[index];
23+
}
24+
25+
public T remove(int index){
26+
T t = this.get(index);
27+
int position = size - index - 1; //why ?
28+
if (position > 0){
29+
System.arraycopy(elementData, index+1, elementData,
30+
index, position);
31+
}
32+
elementData[--size] = null;
33+
return t;
34+
}
35+
36+
public int size(){
37+
return size;
38+
}
39+
40+
//??
41+
public Iterator iterator(){
42+
return null;
43+
}
44+
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class BinaryTreeNode <T extends Comparable> {
2+
private T data;
3+
private BinaryTreeNode left;
4+
private BinaryTreeNode right;
5+
private int size;
6+
public T getData() {
7+
return data;
8+
}
9+
10+
public void setData(T data) {
11+
this.data = data;
12+
}
13+
public BinaryTreeNode getLeft() {
14+
return left;
15+
}
16+
public void setLeft(BinaryTreeNode left) {
17+
this.left = left;
18+
}
19+
public BinaryTreeNode getRight() {
20+
return right;
21+
}
22+
public void setRight(BinaryTreeNode right) {
23+
this.right = right;
24+
}
25+
26+
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public interface Iterator<T> {
2+
public boolean hasNext();
3+
public T next();
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
public class LinkedList<T> implements List<T> {
2+
3+
private Node head;
4+
private Node tail;
5+
private int size;
6+
7+
public void add(T o){
8+
Node node = new Node(o);
9+
if(head == null)
10+
{
11+
head = node;
12+
}
13+
else
14+
{
15+
tail.next = node;
16+
}
17+
tail = node;
18+
tail.next = null;
19+
size++;
20+
21+
}
22+
public void add(int index , T o){
23+
Node node = new Node(o);
24+
Node temp = head;
25+
Node tempTemp = null;
26+
for(int i = 0; i <= index; i++)
27+
{
28+
temp = temp.next;
29+
}
30+
tempTemp = temp.next;
31+
temp.next = node;
32+
node.next = tempTemp;
33+
size++;
34+
}
35+
public T get(int index){
36+
Node temp = head;
37+
for(int i = 0; i <= index; i++)
38+
{
39+
temp = temp.next;
40+
}
41+
return (T)temp.data;
42+
}
43+
public T remove(int index){
44+
if(index == 0){
45+
T o = (T) removeFirst();
46+
return o;
47+
}
48+
Node temp = head;
49+
Node tempTemp = null;
50+
for(int i = 0; i <= index; i++)
51+
{
52+
temp = temp.next;
53+
}
54+
T o = (T) temp.next.data;
55+
tempTemp = temp.next.next;
56+
temp.next = null;
57+
temp.next = tempTemp;
58+
size--;
59+
return o;
60+
}
61+
62+
public int size(){
63+
return size;
64+
}
65+
66+
@Override
67+
public boolean isEmpty() {
68+
return false;
69+
}
70+
71+
public void addFirst(T o){
72+
Node node = new Node(o);
73+
node.next = head;
74+
head = node;
75+
size++;
76+
}
77+
public void addLast(T o){
78+
this.add(o);
79+
}
80+
public T removeFirst(){
81+
T o = (T) head.data;
82+
head = head.next;
83+
size--;
84+
return o;
85+
}
86+
public Object removeLast(){
87+
Node temp = head;
88+
for(int i = 0; i <= size; i++)
89+
{
90+
temp = temp.next;
91+
}
92+
temp.next = null;
93+
T o = (T) tail.data;
94+
tail = temp;
95+
size--;
96+
return o;
97+
}
98+
public Iterator iterator(){
99+
return null;
100+
}
101+
102+
103+
private class Node{
104+
T data;
105+
Node next;
106+
107+
public Node(T o) {
108+
}
109+
}
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public interface List<T> {
2+
public void add(T object);
3+
public void add(int index, T object);
4+
public T get(int index);
5+
public T remove(int index);
6+
public int size();
7+
boolean isEmpty();
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Queue<T> {
2+
3+
private LinkedList<T> element = new LinkedList<T>();
4+
5+
6+
7+
public void enQueue(T o){
8+
element.addLast(o);
9+
}
10+
11+
public T deQueue(){
12+
return element.removeFirst();
13+
}
14+
15+
public boolean isEmpty(){
16+
return element.isEmpty();
17+
}
18+
19+
public int size(){
20+
return element.size();
21+
}
22+
}

group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java

-75
This file was deleted.

0 commit comments

Comments
 (0)