Skip to content

Commit

Permalink
Merge pull request #55 from GUK0/master
Browse files Browse the repository at this point in the history
添加第6周作业文件
  • Loading branch information
guodongym authored Apr 12, 2017
2 parents 3a5f381 + 9562cee commit 5ed3887
Show file tree
Hide file tree
Showing 60 changed files with 1,641 additions and 276 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package week1;
package structure.week1;

import java.util.Collection;

public class ArrayList<E> implements List<E> {
import structure.week1.List;

public class ArrayList<E>{
private int size=0,offset=10;
private Object[] data = null;
public ArrayList(){
Expand All @@ -13,7 +15,7 @@ public ArrayList(int arg0){
size = arg0;
data = new Object[size];
}
@Override

public void add(Object arg0) {
size += 1;
int leng = data.length;
Expand All @@ -27,8 +29,7 @@ public void add(Object arg0) {
data[size-1] = arg0;
}

@Override
public void add(int arg0, E arg1) {
public void add(int arg0, E arg1) {
if( arg0>size || 0<arg0) return ;
size += 1;
int leng = data.length;
Expand Down Expand Up @@ -106,7 +107,6 @@ public boolean containsAll(Collection<?> arg0) {
return true;
}

@Override
public E get(int arg0) {
if(arg0 >-1 && arg0<this.size) return (E)data[arg0];
return null;
Expand Down Expand Up @@ -145,7 +145,6 @@ public boolean remove(Object arg0) {
return false;
}

@Override
public E remove(int arg0) {
if(arg0<0 ||arg0>this.size-1) return null;
E res = (E)data[arg0];
Expand Down Expand Up @@ -174,22 +173,9 @@ public E set(int arg0, E arg1) {
return arg1;
}

@Override
public int size() {
return this.size;
}

public List<E> subList(int arg0, int arg1) {
if(arg0>=arg1 || arg0<0 || arg1>this.size-1) return null;
List<E> res = new ArrayList<E>();
for(int i=arg0;i<arg1;i++){
// 如何获取拷贝?


}

return null;
}
//////////////////////////////////////////////
public Object[] toArray() {
if(this.size == 0) return null;
Expand All @@ -207,12 +193,10 @@ public <T> T[] toArray(T[] arg0) {
}
return res;
}
@Override
public boolean hasNext() {
// TODO 自动生成的方法存根
return false;
}
@Override
public Object next() {
// TODO 自动生成的方法存根
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package structure.week1;

public class BinaryTreeNode {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package structure.week1;

public interface Iterator <E>{
public boolean hasNext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package week1;
package structure.week1;

import java.util.Collection;

public class LinkedList<E> implements List<E> {
public class LinkedList<E> {
private Node head = null;
private Node tail = null;
private int size = 0;
Expand Down Expand Up @@ -36,7 +36,6 @@ public Object clone(){
}
return clone;
}
@Override
public void add(Object val) {
Node n = new Node(val);
n.next = tail;
Expand All @@ -46,7 +45,6 @@ public void add(Object val) {
size += 1;
}

@Override
public void add(int arg0, E arg1) {
if(arg0<0 || arg0>size) arg0=0;
Node n=new Node(arg1),p=head;
Expand Down Expand Up @@ -104,7 +102,6 @@ public boolean containsAll(Collection<?> arg0) {
return true;
}

@Override
public E get(int arg0) {
E res = null;
if(arg0>-1 && arg0 < size){
Expand Down Expand Up @@ -167,7 +164,6 @@ public boolean remove(Object arg0) {
return true;
}

@Override
public E remove(int arg0) {
Node n = head;
if(arg0 <0 || arg0>size-1) return null;
Expand Down Expand Up @@ -202,7 +198,6 @@ public E set(int arg0, E arg1) {
return (E)(n.next.val);
}

@Override
public int size() {
return size;
}
Expand Down Expand Up @@ -231,11 +226,11 @@ private static class Node{
Node next = null,ahead=null;
public Node(Object arg0){val = arg0;}
}
@Override

public boolean hasNext() {
return false;
}
@Override

public Object next() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package week1;
package structure.week1;

public interface List<E> extends Iterator{
public void add(Object o);
public void add(int index, E o);
public E get(int index);
public E remove(int index);
public int size();
void add(int arg0, E arg1);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package structure.week1;
public class Queue<E> {
private LinkedList<E> data = new LinkedList<E>();
public void enQueue(E arg0){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package week1;
package structure.week1;

import week1.List;
import structure.week1.List;

public class Stack<E> {
private ArrayList<E> data = new ArrayList<E>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package week2;
import week1.ArrayList;
package structure.week2;
import structure.week1.ArrayList;

public class ArrayUtil {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week2;
package structure.week2;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package week3;
package structure.week3;


import java.util.NoSuchElementException;

import week1.Iterator;
import week1.List;
import structure.week1.Iterator;
import structure.week1.List;

public class LinkedList implements List {
private Node head = new Node();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3;
package structure.week3;

import static org.junit.Assert.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package week5;
package structure.week5;
import java.util.HashSet;

import week1.ArrayList;
public class LRU {
import structure.week1.ArrayList;
public class LRUPageFrame {
int size;
Node head = new Node(0);
HashSet<Integer> lib = new HashSet<Integer>();
Expand All @@ -14,7 +14,7 @@ public Node(int _val){
next = null;
}
}
public LRU(int _size){
public LRUPageFrame(int _size){
if(_size>0) {
this.size = _size;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week5;
package structure. week5;

import static org.junit.Assert.*;

Expand All @@ -7,7 +7,7 @@
import org.junit.Before;
import org.junit.Test;

public class LRUTest {
public class LRUPageFrameTest {

@Before
public void setUp() throws Exception {
Expand All @@ -19,7 +19,7 @@ public void tearDown() throws Exception {

@Test
public void testAdd() {
LRU lru = new LRU(5);
LRUPageFrame lru = new LRUPageFrame(5);
lru.add(3);
lru.add(7);
lru.add(5);
Expand Down
Loading

0 comments on commit 5ed3887

Please sign in to comment.