Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,27 @@
##CPU,内存,硬盘,指令以及它们之间的关系(2017.03.12)

>对这块也说不太深,大体写点吧

### CPU

CPU,就是中央处理器(Central Processing Unit),就是一大块集成电路 :)

这里面呢,有这么几个重要的东西:ALU、寄存器、时钟。

ALU:就是算数逻辑单元,我的理解,功能上就是把几个基本的逻辑计算、数学计算以电路形式实现出来。比如加法啊、与或非门啊、位移啊什么的。

寄存器:听名字,就是存储用的,保存要干的任务、给ALU提供输入、保存ALU的输出。

时钟:这个。。。,就是一个计时器。为啥需要这个计时器呢(按照上面讲的,运算已经都够完成了)?可以理解为乐队的指挥、龙舟上的鼓手,作用就是产生一个频率信号,用来指挥上面那俩按照一个节奏有序的工作。为了快速的完成任务,这个频率需要非常快,有多快呢?目前3.5GHz已经很常见了,也就是说1s运算350,000,000次。

### 内存

内存呢,也是用来存储数据的。前面说了,CPU里面已经有了寄存器这么个用来存储的东西,为啥还要个内存呢?主要原因就是寄存器又小又贵,小到不能存储所有的内容(基本上存不了什么),贵到不好任性的扩容(要满足CPU那么快的速度还是有难度的)。有人就想出了另一种方案,把不那么常用的数据呢,放在不那么快,但是更大的存储原件里面,也就是内存。平常存储点堆栈啊、缓冲什么的。这样,寄存器只要保存数据在内存中的位置,用的时候去内存取出来就好了。内存还可以分为RAM与ROM,不再细说。

### 硬盘

要硬盘,是因为内存也不够用了。。。当然,硬盘比内存还要慢,一般也会比内存大。用的时候,先从硬盘读出来放到内存就好了。

### 指令

指令,就是给CPU用的Java(当然写起来远没有Java方便),用来告诉CPU要干什么。
12 changes: 12 additions & 0 deletions group22/910725683/RemoteSystemsTempFiles/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RemoteSystemsTempFiles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions group22/910725683/week01/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
4 changes: 4 additions & 0 deletions group22/910725683/week01/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin/
/.settings/
.classpatch
.prject
17 changes: 17 additions & 0 deletions group22/910725683/week01/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>week01</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
98 changes: 98 additions & 0 deletions group22/910725683/week01/src/com/coding/basic/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.coding.basic;
import java.util.Arrays;

public class ArrayList implements List {

//�����ʼ����//
private final int DEFAULT_CAPICITY=7;

//����Ԫ�ظ���//
private int size = 0;

private Object[] elementData = new Object[DEFAULT_CAPICITY];

public void add(Object o){
ensureCapcity(size+1);
elementData[size++]=o;
}
public void add(int index, Object o){
//indexҪ����������//
checkIndex(index);
ensureCapcity(size+1);
/* index�������Ԫ������һλ,����index��ʼ�ƶ���ע��index��0��ʼ��
* ����Ҫ+1���򳤶�Ϊsize-((index)+1)+1
*/
System.arraycopy(elementData, index, elementData, index+1, size-index);
elementData[index]=o;
size++;
}

public Object get(int index){
checkIndex(index);
return elementData[index];
}

public Object remove(int index){
checkIndex(index);
Object temp=elementData[index];
/* index�����Ԫ������һλ,����index+1��ʼ�ƶ���ע��index��0��ʼ��
* ����Ҫ+1���򳤶�Ϊsize-((index+1)+1)+1
*/
System.arraycopy(elementData, index+1, elementData, index, size-index-1);
size--;
return temp;
}

public int size(){
return size;
}

public Iterator iterator(){
return new Iterator();
}

private class Iterator{
private int index=0;
public boolean hasNext(){
return index<size;
}
public Object next(){
checkIndex(index);
return elementData[index++];
}
}

//�ж�������±��Ƿ�Խ�粢��ʾ//
private void checkIndex(int index){
if (index<0 || index >=size){
throw new IndexOutOfBoundsException("get " + index+" in "+size);
}
}

//�ж��Ƿ���Ҫ���ݲ��������//
private void ensureCapcity(int size){
int oldLength=elementData.length;
if (size>=oldLength){
//util.ArrayList�еĹ�ʽ��Դ����ʹ�õ�����1������2//
int newLength=oldLength/2+oldLength;
if (newLength<size){
newLength=size;
}
//Arrays.copyOf�����µ�ָ�����ȵ�����//
elementData=Arrays.copyOf(elementData, newLength);
}
}

@Override
public String toString(){
//���������toString//
StringBuilder sb = new StringBuilder("[");
for (int i=0 ;i<size-1;i++){
sb.append(elementData[i]+",");
}
sb.append(elementData[size-1]);
sb.append("]");
return sb.toString();
}

}
110 changes: 110 additions & 0 deletions group22/910725683/week01/src/com/coding/basic/BinaryTreeNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.coding.basic;

/**
* ʵ������һ������������BinarySearchTree
*/
public class BinaryTreeNode {

//���ڵ�this//
private Object data;
private BinaryTreeNode left;
private BinaryTreeNode right;

public BinaryTreeNode () {}

public BinaryTreeNode(Object o) {
this.data=o;
this.left=null;
this.right=null;
}

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 void preOrder(BinaryTreeNode node) {
if (node.data!=null) {
System.out.print(node.data + " ");
if (node.left!=null) {
preOrder(node.left);
}
if (node.right!=null) {
preOrder(node.right);
}
}
}

//��������������//
public void inOrder(BinaryTreeNode node) {
if (node.data!=null) {
if (node.left!=null) {
inOrder(node.left);
}
System.out.print(node.data + " ");
if (node.right!=null) {
inOrder(node.right);
}
}
}

//������������Ҹ�//
public void postOrder(BinaryTreeNode node) {
if (node.data!=null) {
if (node.left!=null) {
postOrder(node.left);
}
if (node.right!=null) {
postOrder (node.right);
}
System.out.print(node.data + " ");
}
}

public BinaryTreeNode insert(Object o){
//�ȿ������ڵ��Dz��ǿյ�//
if (this.data==null){
this.data=o;
return this;
}else{
//С��ȥ��ߣ����ȥ�ұ�//
if ((int) o < (int) this.data){
/*������ǿյ��Ǿ������ˣ�����һ���µĽڵ�
*����߲��ǿյ�����������ҿյ�
*/
if (this.left==null){
this.left = new BinaryTreeNode(o);
return this.left;
}else{

return this.left.insert(o);
}
}else{
/*���ұ��ǿյ��Ǿ������ˣ�����һ���µĽڵ�
*���ұ߲��ǿյ�����������ҿյ�
*/
if (this.right==null){
this.right = new BinaryTreeNode(o);
return this.right;
}else{
return this.right.insert(o);
}
}
}
}
}
7 changes: 7 additions & 0 deletions group22/910725683/week01/src/com/coding/basic/Iterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.coding.basic;

public interface Iterator {
public boolean hasNext();
public Object next();

}
Loading