-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from northSmall/master
T.north
- Loading branch information
Showing
9 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,12 @@ hs_err_pid* | |
/.idea | ||
/**/target/**/* | ||
|
||
*target | ||
*.classpath | ||
*.project | ||
*.settings | ||
*iml | ||
.idea | ||
*gen-* | ||
rebel.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
指令就是计算机直接用来控制计算机运行的代码,我们编写的java代码,在实际运行时也会被计算机在底层转化为各式各样的指令。 | ||
而cpu就是负责读取并解释这些指令的设备,cpu主要由几大部分组长,包括运算器、控制器和寄存器,控制器负责把指令、数据读取寄存器,运算器负责运算寄存器中的数据。但由于内存容量有限,成本高,并且断电之后里面的一切数据都会丢失,导致内存并不能作为我们永久存储程序的地方,而硬盘的价格便宜、容量大、断电后仍能保存数据,就可以作为我们长期存储程序和其他数据的地方。当我们需要运行某一个程序的时候,就从硬盘中将对应的数据读取到内存中,然后CPU再从内存中读取执行。 | ||
cpu如果直接读取硬盘数据,由于硬盘的速度比内存慢了太多,会导致计算机运算能力严重降低。 |
53 changes: 53 additions & 0 deletions
53
group19/604322962/learning2017/src/main/java/com/coding/basic/ArrayList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main.java.com.coding.basic; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
private static final int GORW_CAPACITY = 10; | ||
public void add(Object o){ | ||
if (size<elementData.length) | ||
elementData[size++] = o; | ||
else { | ||
elementData = Arrays.copyOf(elementData, elementData.length+GORW_CAPACITY); | ||
elementData[size++] = o; | ||
} | ||
} | ||
public void add(int index, Object o){ | ||
checkIndex(index); | ||
System.arraycopy(elementData, index, elementData, index + 1, | ||
size - index); | ||
elementData[index] = o; | ||
} | ||
|
||
public Object get(int index){ | ||
checkIndex(index); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
checkIndex(index); | ||
Object obj = elementData[index]; | ||
System.arraycopy(elementData, index+1, elementData, index, | ||
size - index-1); | ||
return obj; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
private void checkIndex(int index){ | ||
if (index>elementData.length) | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
group19/604322962/learning2017/src/main/java/com/coding/basic/BinaryTreeNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main.java.com.coding.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
private Object data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
|
||
public Object getData() { | ||
return data; | ||
} | ||
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
public BinaryTreeNode getLeft() { | ||
return left; | ||
} | ||
public void setLeft(BinaryTreeNode left) { | ||
this.left = left; | ||
} | ||
public BinaryTreeNode getRight() { | ||
return right; | ||
} | ||
public void setRight(BinaryTreeNode right) { | ||
this.right = right; | ||
} | ||
|
||
public BinaryTreeNode insert(Object o){ | ||
return null; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
group19/604322962/learning2017/src/main/java/com/coding/basic/Iterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main.java.com.coding.basic; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
143 changes: 143 additions & 0 deletions
143
group19/604322962/learning2017/src/main/java/com/coding/basic/LinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package main.java.com.coding.basic; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private int size; | ||
private Node tail; | ||
public void add(Object obj){ | ||
linkLast(obj); | ||
} | ||
|
||
public void add(int index , Object obj){ | ||
if (index<0 || index>size) | ||
throw new IndexOutOfBoundsException(); | ||
else { | ||
if (index == size) | ||
linkLast(obj); | ||
else { | ||
Node node = linkIndex(index);//获取指定index的Node | ||
Node pred = node.prev; | ||
Node newNode = new Node(node.prev,obj,node); | ||
node.prev = newNode; | ||
if (pred==null) | ||
head = newNode; | ||
else | ||
node.prev.next = newNode;//原链表指定节点前一个的节点的next指向新节点 | ||
size++; | ||
} | ||
} | ||
} | ||
public Object get(int index){ | ||
return linkIndex(index); | ||
} | ||
public Object remove(int index){ | ||
Node node = linkIndex(index);//获取指定index的Node | ||
Node prev = node.prev; | ||
Node next = node.next; | ||
if (prev==null) { | ||
//此时删除的节点为头节点 | ||
head = next; | ||
} else { | ||
prev.next = next; | ||
node.prev = null; | ||
} | ||
if (next==null) { | ||
//此时删除节点为尾节点 | ||
tail = prev; | ||
} else { | ||
next.prev = prev; | ||
node.next = null; | ||
} | ||
node.data = null; | ||
size--; | ||
return node; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
Node newNode = new Node(null,o, head); | ||
if (head == null) { | ||
head = newNode; | ||
} else { | ||
newNode.next = head; | ||
} | ||
size++; | ||
} | ||
public void addLast(Object o){ | ||
Node newNode = new Node(head,o, null); | ||
if (head == null) { | ||
head = newNode; | ||
} else { | ||
newNode.next = head; | ||
} | ||
size++; | ||
} | ||
public Object removeFirst(){ | ||
if (head == null) { | ||
throw new NoSuchElementException(); | ||
} else { | ||
Node next = head.next; | ||
Object obj = head.data; | ||
head.next = null; | ||
head.data = null; | ||
head = next; | ||
if (next == null) { | ||
tail = null; | ||
} else { | ||
next.prev = null; | ||
} | ||
size--; | ||
return obj; | ||
} | ||
} | ||
public Object removeLast(){ | ||
tail = tail.prev; | ||
head.next = null; | ||
head.data = null; | ||
return tail; | ||
} | ||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
/** | ||
* 尾部添加一个节点 | ||
* @param obj | ||
*/ | ||
private void linkLast(Object obj){ | ||
Node newNode = new Node(tail,obj, null); | ||
if (tail == null) { | ||
head = newNode; | ||
tail = newNode; | ||
} else | ||
tail.next = newNode; | ||
size++; | ||
} | ||
/** | ||
* 获取指定index索引的Node节点 | ||
* @param index | ||
* @return | ||
*/ | ||
private Node linkIndex(int index){ | ||
Node n = head; | ||
for (int i=0;i<index;i++) | ||
n = n.next; | ||
return n; | ||
} | ||
private static class Node{ | ||
Object data; | ||
Node prev; | ||
Node next; | ||
Node(Node prev,Object obj, Node next){ | ||
this.prev = prev; | ||
this.data = obj; | ||
this.next = next; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
group19/604322962/learning2017/src/main/java/com/coding/basic/List.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main.java.com.coding.basic; | ||
|
||
public interface List { | ||
public void add(Object o); | ||
public void add(int index, Object o); | ||
public Object get(int index); | ||
public Object remove(int index); | ||
public int size(); | ||
} |
52 changes: 52 additions & 0 deletions
52
group19/604322962/learning2017/src/main/java/com/coding/basic/Queue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main.java.com.coding.basic; | ||
|
||
import org.junit.Test; | ||
|
||
public class Queue { | ||
|
||
private Object[] objArray; | ||
private int front=0;//队列头指针 | ||
private int rear=-1;//队列尾指针 | ||
private int maxSize;//队列最大长度 | ||
private int size=0;//队列长度 | ||
public Queue(int maxSize){ | ||
this.maxSize = maxSize; | ||
this.objArray= new Object[maxSize]; | ||
} | ||
public Queue(){} | ||
public void enQueue(Object obj){ | ||
if (rear == maxSize-1) | ||
rear = -1; | ||
objArray[++rear] = obj; | ||
size++; | ||
} | ||
|
||
public Object deQueue(){ | ||
if (front == maxSize) | ||
front = 0; | ||
size--; | ||
return objArray[front++]; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return size()==0; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
@Test | ||
public void test(){ | ||
//单元测试时,需要注释掉带参数构造函数 | ||
Queue queue = new Queue(); | ||
queue.enQueue("lisi"); | ||
queue.enQueue("zhangsan"); | ||
queue.enQueue("wangwu"); | ||
queue.enQueue("zhaoliu"); | ||
for (int i=0;i<4;i++) { | ||
String name = (String)queue.deQueue(); | ||
System.out.println(name); | ||
} | ||
|
||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
group19/604322962/learning2017/src/main/java/com/coding/basic/Stack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main.java.com.coding.basic; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.EmptyStackException; | ||
import java.util.NoSuchElementException; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
private int top = -1; | ||
public void push(Object o){ | ||
elementData.add(++top); | ||
} | ||
public Object pop(){ | ||
Object obj = elementData.get(top--); | ||
elementData.remove(top); | ||
return obj; | ||
} | ||
public Object peek(){ | ||
if (size() == 0) | ||
throw new EmptyStackException(); | ||
return elementData.get(size()-1); | ||
} | ||
public boolean isEmpty(){ | ||
return size()==0; | ||
} | ||
public int size(){ | ||
return top+1; | ||
} | ||
@Test | ||
public void test(){ | ||
int[] elementData = {1,2,4,5,6,7}; | ||
int[] newArray = new int[10]; | ||
int index = 2; | ||
System.arraycopy(elementData,index,newArray,index+1,4); | ||
newArray[2] = 3; | ||
System.out.println(newArray.length); | ||
for (int data : | ||
newArray) { | ||
System.out.println(data); | ||
} | ||
} | ||
} |