-
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 #8 from drunbility/master
20组组员浮云提交作业
- Loading branch information
Showing
11 changed files
with
429 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
对计算机硬件的理解 | ||
计算机中cpu是核心部件,cpu是主要的计算部件,所有的逻辑运算和算术运算都是由cpu来玩成的。但cpu只管运算,怎么运算,何时运算,运算什么这些cpu都是不管的,这些其实就是一个个的指令,指令用来表示所有运算的信息,包括做什么运算,运算什么,运算结果如何处置等。这些指令都是存在内存当中的,cpu按照一定的顺序从内存当中读取指令,执行指令做运算,然后按照相应的指令输出结果。这就是一个简单的程序运行过程。内存空间是有限的,另外,内存上的指令也不能持久化的保存,断电之后就没有了。所以需要一个硬件保存大的二进制资源以及持久化的保存指令,所以就有了硬盘。所以计算机先从硬盘中读取指令和资源到内存当中来,然后cpu再从内存当中读取指令和资源,做运算,运算完之后再按照指令将输出保存在内存中或者硬盘中,程序执行完毕。 |
56 changes: 56 additions & 0 deletions
56
group20/755659358/liuxincourse_datastructure/src/liuxincourse/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,56 @@ | ||
package liuxincourse; | ||
|
||
import java.util.Arrays; | ||
|
||
|
||
public class ArrayList implements List{ | ||
|
||
private int size=0; | ||
|
||
private Object [] elementDataObjects = new Object[3]; | ||
|
||
public void add (Object o){ | ||
if (size>=elementDataObjects.length) { | ||
elementDataObjects=Arrays.copyOf(elementDataObjects, elementDataObjects.length+50); | ||
} | ||
elementDataObjects[size]=o; | ||
size++; | ||
} | ||
|
||
public void add (int index ,Object o){ | ||
if (index>=size||index<0) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
if (size>=elementDataObjects.length) { | ||
elementDataObjects=Arrays.copyOf(elementDataObjects, elementDataObjects.length+50); | ||
} | ||
System.arraycopy(elementDataObjects, index, elementDataObjects, index+1, size-index); | ||
elementDataObjects[index]=o; | ||
size++; | ||
} | ||
|
||
public Object get (int index){ | ||
if (index>=size||index<0) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
return elementDataObjects[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
if (index>=size||index<0) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
Object rem=elementDataObjects[index]; | ||
System.arraycopy(elementDataObjects, index+1, elementDataObjects, index, size-index-1); | ||
size--; | ||
return rem; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
// public Iterator iterator(){ | ||
// | ||
// } | ||
} |
120 changes: 120 additions & 0 deletions
120
group20/755659358/liuxincourse_datastructure/src/liuxincourse/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,120 @@ | ||
package liuxincourse; | ||
|
||
|
||
public class LinkedList implements List{ | ||
|
||
private Node head; | ||
|
||
private int size=0; | ||
|
||
|
||
public void add(Object o){ | ||
if (size==0) { | ||
head=new Node(); | ||
head.data=o; | ||
size++; | ||
return; | ||
} | ||
Node last=head; | ||
for (int i = 0; i < size-1; i++) { | ||
last=last.next; | ||
} | ||
Node added=new Node(); | ||
last.next=added; | ||
added.data=o; | ||
size++; | ||
} | ||
|
||
public void add(int index,Object o){ | ||
if (index<0||index>size) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
Node pre=getNode(index-1); | ||
Node next=getNode(index); | ||
Node addedNode=new Node(); | ||
addedNode.data=o; | ||
pre.next=addedNode; | ||
addedNode.next=next; | ||
size++; | ||
} | ||
|
||
private Node getNode(int index){ | ||
Node node=head; | ||
|
||
for (int i = 0; i < index; i++) { | ||
node=node.next; | ||
} | ||
|
||
return node; | ||
} | ||
|
||
public Object get(int index){ | ||
if (index<0||index>size-1) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
if (index==0&&head==null) { | ||
return null; | ||
} | ||
return getNode(index).data; | ||
|
||
} | ||
|
||
public Object remove(int index) { | ||
if (index<0||index>size-1) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
Node pre=getNode(index-1); | ||
Node next=getNode(index+1); | ||
pre.next=next; | ||
return getNode(index); | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
if (head==null) { | ||
head=new Node(); | ||
head.data=o; | ||
size++; | ||
return; | ||
} | ||
Node addNode=new Node(); | ||
addNode.data=o; | ||
addNode.next=head; | ||
head=addNode; | ||
size++; | ||
} | ||
|
||
public void addLast(Object o){ | ||
Node preLast=getNode(size-1); | ||
Node addNode=new Node(); | ||
addNode.data=o; | ||
preLast.next=addNode; | ||
size++; | ||
} | ||
|
||
public Object removeFirst(){ | ||
Node preHead=head; | ||
head=head.next; | ||
size--; | ||
return preHead.data; | ||
} | ||
|
||
public Object removeLast(){ | ||
Node preLast=getNode(size-1); | ||
Node last=getNode(size-2); | ||
last.next=null; | ||
size--; | ||
return preLast.data; | ||
} | ||
|
||
private static class Node{ | ||
|
||
Object data; | ||
Node next; | ||
|
||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
group20/755659358/liuxincourse_datastructure/src/liuxincourse/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,10 @@ | ||
package liuxincourse; | ||
|
||
public interface List { | ||
|
||
void add(Object o); | ||
void add(int index,Object o); | ||
Object get(int index); | ||
Object remove(int index); | ||
int size(); | ||
} |
25 changes: 25 additions & 0 deletions
25
group20/755659358/liuxincourse_datastructure/src/liuxincourse/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,25 @@ | ||
package liuxincourse; | ||
|
||
public class Queue { | ||
|
||
LinkedList list=new LinkedList(); | ||
|
||
public void enQueue(Object o){ | ||
list.add(o); | ||
} | ||
|
||
public Object deQueue(){ | ||
|
||
return list.removeFirst(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
|
||
return size()==0?true:false; | ||
} | ||
|
||
public int size(){ | ||
return list.size(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
group20/755659358/liuxincourse_datastructure/src/liuxincourse/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,27 @@ | ||
package liuxincourse; | ||
|
||
public class Stack { | ||
|
||
private LinkedList elementData=new LinkedList(); | ||
|
||
public void push (Object o){ | ||
elementData.addFirst(o); | ||
} | ||
|
||
public Object pop() { | ||
return elementData.removeFirst(); | ||
} | ||
|
||
public Object peek(){ | ||
return elementData.get(0); | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return size()==0?true:false; | ||
} | ||
|
||
public int size() { | ||
return elementData.size(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
group20/755659358/liuxincourse_datastructure/test/liuxincourse/ArrayListTest.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 liuxincourse; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
public class ArrayListTest { | ||
|
||
|
||
@Test | ||
public void testAdd(){ | ||
ArrayList list=new ArrayList(); | ||
list.add(12); | ||
list.add(2); | ||
list.add(8); | ||
assertEquals(8, list.get(2)); | ||
} | ||
|
||
@Test | ||
public void testAddIndex(){ | ||
ArrayList list=new ArrayList(); | ||
list.add(12); | ||
list.add(2); | ||
list.add(8); | ||
list.add(1,33); | ||
list.add(6); | ||
list.add(7); | ||
assertEquals(8, list.get(3)); | ||
} | ||
|
||
@Test | ||
public void testRemove(){ | ||
ArrayList list=new ArrayList(); | ||
list.add(12); | ||
list.add(2); | ||
list.add(8); | ||
list.add(1,33); | ||
list.remove(1); | ||
assertEquals(2, list.get(1)); | ||
} | ||
|
||
@Test | ||
public void testSize(){ | ||
ArrayList list=new ArrayList(); | ||
list.add(12); | ||
list.add(2); | ||
list.add(8); | ||
list.add(9); | ||
list.add(77); | ||
assertEquals(5, list.size()); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
group20/755659358/liuxincourse_datastructure/test/liuxincourse/LinkedListTest.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,69 @@ | ||
package liuxincourse; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
public class LinkedListTest { | ||
|
||
@Test | ||
public void testAdd() { | ||
LinkedList list=new LinkedList(); | ||
list.add(33); | ||
list.add(44); | ||
list.add(55); | ||
list.add(88); | ||
assertEquals(88, list.get(3)); | ||
} | ||
|
||
@Test | ||
public void testAddIndex() { | ||
LinkedList list=new LinkedList(); | ||
list.add(33); | ||
list.add(44); | ||
list.add(55); | ||
list.add(1, 88); | ||
assertEquals(55, list.get(3)); | ||
} | ||
|
||
@Test | ||
public void testAddFirst() { | ||
LinkedList list=new LinkedList(); | ||
list.add(33); | ||
list.add(44); | ||
list.add(55); | ||
list.addFirst(88); | ||
assertEquals(88, list.get(0)); | ||
} | ||
|
||
@Test | ||
public void testAddLast() { | ||
LinkedList list=new LinkedList(); | ||
list.add(33); | ||
list.add(44); | ||
list.add(55); | ||
list.addFirst(88); | ||
list.addLast(00); | ||
assertEquals(00, list.get(list.size()-1)); | ||
} | ||
|
||
@Test | ||
public void testRemoveFirst() { | ||
LinkedList list=new LinkedList(); | ||
list.add(33); | ||
list.add(44); | ||
list.add(55); | ||
list.addFirst(88); | ||
assertEquals(88, list.removeFirst()); | ||
} | ||
|
||
@Test | ||
public void testRemoveLast() { | ||
LinkedList list=new LinkedList(); | ||
list.add(33); | ||
list.add(44); | ||
list.add(55); | ||
list.addFirst(88); | ||
assertEquals(55, list.removeLast()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
group20/755659358/liuxincourse_datastructure/test/liuxincourse/QueueTest.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,27 @@ | ||
package liuxincourse; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
public class QueueTest { | ||
|
||
@Test | ||
public void testEnqueue() { | ||
Queue queue=new Queue(); | ||
queue.enQueue(11); | ||
queue.enQueue(22); | ||
assertEquals(11, queue.deQueue()); | ||
} | ||
|
||
@Test | ||
public void testIsempty() { | ||
Queue queue=new Queue(); | ||
queue.enQueue(11); | ||
queue.enQueue(22); | ||
queue.deQueue(); | ||
queue.deQueue(); | ||
assertEquals(true, queue.isEmpty()); | ||
} | ||
|
||
} |
Oops, something went wrong.