Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

八组作业提交 #23

Merged
merged 46 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
988fb24
基本数据结构作业提交
BlankKelly Feb 25, 2017
f999553
基本数据结构作业
BlankKelly Feb 25, 2017
cc242d8
delete unuseful file
BlankKelly Feb 25, 2017
7c83996
fix some problem
BlankKelly Feb 25, 2017
77e6746
finish ArrayList\'s iterator method
BlankKelly Feb 25, 2017
0c2543d
Add files via upload
zzkmz Feb 25, 2017
9cf0c3a
Create 文章
zzkmz Feb 25, 2017
3081df9
2-26 assignment
mingming-lu Feb 25, 2017
d69a64d
Create aa
zzkmz Feb 26, 2017
a34d8bb
Add files via upload
zzkmz Feb 26, 2017
b63412e
Create 文章
zzkmz Feb 26, 2017
da84e68
Delete aa
zzkmz Feb 26, 2017
aaee175
Delete ArrayList.java
zzkmz Feb 26, 2017
f7577be
Delete Iterator.java
zzkmz Feb 26, 2017
880f2c9
Delete LinkedList.java
zzkmz Feb 26, 2017
ca9b3c2
Delete List.java
zzkmz Feb 26, 2017
d664387
Delete Queue.java
zzkmz Feb 26, 2017
25b99c4
Delete Stack.java
zzkmz Feb 26, 2017
4a8b6cc
Delete zzk.md
zzkmz Feb 26, 2017
437ac94
Delete 文章
zzkmz Feb 26, 2017
6fd6284
Merge pull request #25 from zzkmz/master
Greastate Feb 26, 2017
4f52a98
Merge pull request #24 from akinaru-lu/master
Greastate Feb 26, 2017
bc46fec
Merge pull request #1 from Greastate/master
BigBangGe Feb 26, 2017
fed426b
delete all files
BlankKelly Feb 26, 2017
cde4416
commit 02-27 homework
BlankKelly Feb 26, 2017
d494df3
Merge pull request #1 from Greastate/master
BlankKelly Feb 26, 2017
9549ba9
add README.md
BlankKelly Feb 26, 2017
fcfc572
Merge branch 'master' of github.com:BlankKelly/coding2017
BlankKelly Feb 26, 2017
cea1d63
delete file
BlankKelly Feb 26, 2017
0fafcb9
delete file
BlankKelly Feb 26, 2017
b394c4e
Merge pull request #26 from BlankKelly/master
Greastate Feb 26, 2017
be3ef60
Merge pull request #2 from Greastate/master
BigBangGe Feb 26, 2017
2ca2147
新建list类
Feb 26, 2017
317f47a
ArrayList提交
Feb 26, 2017
9434052
commit
twbbb Feb 26, 2017
594a6ed
linkedlist .文章 提交
Feb 26, 2017
fa28c2d
Merge pull request #27 from BigBangGe/master
Greastate Feb 26, 2017
d030831
commit
twbbb Feb 26, 2017
f8ed6ad
commit
twbbb Feb 26, 2017
9816c2e
二叉树
yangyangxu2016 Feb 26, 2017
b520d9b
Merge pull request #29 from yangyangxu2016/master
Greastate Feb 26, 2017
fd9dc90
commit
twbbb Feb 26, 2017
b430ccd
delete
twbbb Feb 26, 2017
55e058d
delete
twbbb Feb 26, 2017
6989227
Merge pull request #31 from twbbb/master
Greastate Feb 27, 2017
3798466
Merge pull request #32 from onlyliuxin/master
Greastate Feb 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## cpu 内存 硬盘 指令之间的关系
> 计算机整体分为软件和硬件。
> 软件是由指令和数据组成的程序,硬件包含主板、CPU、内存、硬盘等


指令指的是计算机可以识别的机器语言,每个操作系统都有内置的指令集,计算机可根据不同的指令来驱动计算机工作或是相应的输出。指令是以二进制的形式存储在硬盘中,当CPU执行某个指令的时候,需要将指令先从硬盘加载到内存,CPU从内存中获取执行解释执行。

CPU是计算的核心部件,相当于人类的大脑。CPU执行指令的时候其实不关心也不知道指令的意思,只是按照指令执行。由于硬盘读写性能比较差,CPU从硬盘中直接读取数据的时候比较费时,就有的内存的存在。内存比硬盘读写速度快很多,CPU要执行程序时,先将程序加载到内存中在执行。
131 changes: 131 additions & 0 deletions group08/121027265/0226/src/com/my/list/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.my.list;

/**
* 实现ArrayList
*
*/
public class ArrayList {
//初始化容量
private static final int INIT = 5;
//增长因子
private static final double GROWTH = 0.5;

//初始化数组
Object[] baseArr = new Object[INIT];
//当前下标
int currentIndex = 0;
//最大下标
int maxIndex = INIT-1;

/**
* 添加元素
* @param obj
* @return
*/
public Object add(Object obj){
if(judgeCapacity()){
baseArr = arrayDilatation(baseArr, GROWTH);
maxIndex = baseArr.length-1;
}
baseArr[currentIndex] = obj;
++currentIndex;
return obj;
}

/**
* 指定下标添加元素
* @param index
* @param obj
* @return
*/
public Object add(int index , Object obj){
if (index < 0 || index > currentIndex) {
throw new IndexOutOfBoundsException();
}
Object[] dest = new Object[currentIndex+1];
System.arraycopy(baseArr, 0, dest, 0, index);
dest[index] = obj;
System.arraycopy(baseArr, index, dest, index+1, currentIndex-index);
++currentIndex;
baseArr = dest;
return obj;
}

/**
* 指定下标删除元素
* @param index
* @return
*/
public Object remove(int index){
if (index < 0 || index >= currentIndex) {
throw new IndexOutOfBoundsException();
}
Object object = baseArr[index];
Object[] dest = new Object[currentIndex];
System.arraycopy(baseArr, 0, dest, 0, index);
System.arraycopy(baseArr, index+1, dest, index, currentIndex-index-1);
--currentIndex;
baseArr = dest;
return object;
}

/**
* 根据下标获取元素
* @param index
* @return
*/
public Object get(int index){

return baseArr[index];
}

/**
* 获取集合大小
* @return
*/
public int size(){
return currentIndex;
}

/**
* 判断容量是否需要增加
* @return
*/
public boolean judgeCapacity(){
if(currentIndex > maxIndex){
return true;
}
return false;
}

/**
* 数组扩容
* @param objArr
* @param groth
* @return
*/
public static Object[] arrayDilatation(Object[] objArr , double groth){
int length = objArr.length;
int newLength = (int) (length * groth + length);
Object[] baseArr = new Object[newLength];
System.arraycopy(objArr, 0, baseArr, 0, length);
return baseArr;
}


}















156 changes: 156 additions & 0 deletions group08/121027265/0226/src/com/my/list/LinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package com.my.list;

/**
* 实现 LinkedList
*
*/
public class LinkedList {

//首节点
Node first = new Node();
//集合大小
int size = 0;

/**
* 添加元素
* @param object
* @return
*/
public Object add(Object object){
if (size == 0) {
first.setObject(object);
}else{
Node previous = first;
Node temp = first.getNext();
while (temp != null) {
previous = temp;
temp = temp.getNext();
}
Node node = new Node();
node.setObject(object);
previous.setNext(node);
}
++size;
return object;
}

/**
* 根据下标添加元素
* @param index
* @param object
* @return
*/
public Object add(int index , Object object){
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException();
}

if (size == 0) {
first.setObject(object);
}else{
if (index == 0) {
Node temp = new Node();
temp.setObject(object);
temp.setNext(first);
first = temp;
}else{
int count = 1;
Node temp = first;
while (temp != null) {
if (count++ == index) {
Node next = temp.getNext();
Node node = new Node();
temp.setNext(node);
node.setObject(object);
node.setNext(next);
break;
}
temp = temp.getNext();
}
}
}
++size;
return object;
}

/**
* 根据下标删除元素
* @param index
* @return
*/
public Object remove(int index){
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
Node node = null;
if (index == 0) {
Node next = first.getNext();
first = next;
node = first;
}else{
int count = 1;
Node temp = first;
while (temp != null) {
if (count++ == index) {
node = temp.getNext();
Node next = node.getNext();
temp.setNext(next);
break;
}
temp = temp.getNext();
}
}
--size;
return node.getObject();
}

/**
* 根据下标获取元素
* @param index
* @return
*/
public Object get(int index) {
Node temp = first;
int count = 0;
while (temp != null) {
if (count++ == index) {
break;
}
temp = temp.getNext();
}
return temp.getObject();
}

/**
* 获取集合大小
* @return
*/
public int size() {
return size;
}


}


/**
* 节点元素
*
*/
class Node{
private Object object ;
private Node next;
public Object getObject() {
return object;
}
public void setObject(Object object) {
this.object = object;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}

}
65 changes: 65 additions & 0 deletions group08/121027265/0226/src/com/my/list/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.my.list;

public class Test {

public static void main(String[] args) {

testArrayList();
System.out.println("--------------------------------");
testLinkedList();
}

/**
* ArrayList 测试
*/
public static void testArrayList(){
System.out.println("ArrayList 测试 --开始");
ArrayList list = new ArrayList();
list.add("123");
list.add("123");
list.add("123");
list.add("123");
list.add("123");
list.add("123");

list.add(1, 111);

list.remove(1);

System.out.println(list.baseArr.length);
System.out.println(list.size());

for (int i = 0; i < list.size(); i++) {
Object object = list.get(i);
System.out.println(object);
}
System.out.println("ArrayList 测试 --结束");
}

/**
* LinkedList 测试
*/
public static void testLinkedList(){
System.out.println("LinkedList 测试 --开始");
LinkedList list = new LinkedList();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);

list.add(1, 111);

list.remove(1);

System.out.println(list.size());

for (int i = 0; i < list.size(); i++) {
Object object = list.get(i);
System.out.println(object);
}
System.out.println("LinkedList 测试 --结束");
}

}
Loading