Skip to content

Commit

Permalink
重构项目代码目录
Browse files Browse the repository at this point in the history
  • Loading branch information
gukz committed Apr 12, 2017
1 parent 6ba808f commit 9562cee
Show file tree
Hide file tree
Showing 64 changed files with 976 additions and 621 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,7 +1,7 @@
package week5;
package structure.week5;
import java.util.HashSet;

import week1.ArrayList;
import structure.week1.ArrayList;
public class LRUPageFrame {
int size;
Node head = new Node(0);
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 Down
133 changes: 133 additions & 0 deletions group12/247565311/structure/week6/StackUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package structure.week6;
import java.util.Stack;
public class StackUtil {

public static void bad_reverse(Stack<Integer> s) {
if(s == null || s.isEmpty()){
return;
}
Stack<Integer> tmpStack = new Stack();
while(!s.isEmpty()){
tmpStack.push(s.pop());
}
s = tmpStack;
}

/**
* 閸嬪洩顔曢弽鍫滆厬閻ㄥ嫬鍘撶槐鐘虫ЦInteger, 娴犲孩鐖ゆい璺哄煂閺嶅牆绨抽弰锟� 5,4,3,2,1 鐠嬪啰鏁ょ拠銉︽煙濞夋洖鎮楅敍锟介崗鍐濞嗏�绨崣妯硅礋: 1,2,3,4,5
* 濞夈劍鍓伴敍姘涧閼虫垝濞囬悽鈯縯ack閻ㄥ嫬鐔�張顒佹惙娴f粣绱濋崡纭僽sh,pop,peek,isEmpty閿涳拷閸欘垯浜掓担璺ㄦ暏閸欙箑顦绘稉锟介嚋閺嶅牊娼垫潏鍛И
*/
public static void reverse(Stack<Integer> s){
if(s == null || s.isEmpty()) return;
int size = 0;
Stack<Integer> s1 = new Stack<Integer>();
while(!s.isEmpty()){
s1.push(s.pop());
size += 1;
}
while(!s1.isEmpty())
s.push(s1.pop());
for(int i=0;i<size;i++){
Integer integer = s.pop();
while(s.size()>i)
s1.push(s.pop());
s.push(integer);
while(s1.size()>0)
s.push(s1.pop());
}
}
// 閫氳繃閫掑綊鍙互涓嶄娇鐢ㄥ爢鏍堝畬鎴愯繖涓�姛鑳�
public static void reverse2(Stack<Integer> s) {
if(s == null || s.isEmpty()){
return;
}
Integer top = s.pop();
reverse(s);
addToBottom(s,top);
}
public static void addToBottom(Stack<Integer> s, Integer value){
if(s.isEmpty()){
s.push(value);
} else{
Integer top = s.pop();
addToBottom(s,value);
s.push(top);
}
}
/**
* 閸掔娀娅庨弽鍫滆厬閻ㄥ嫭鐓囨稉顏勫帗缁憋拷濞夈劍鍓伴敍姘涧閼虫垝濞囬悽鈯縯ack閻ㄥ嫬鐔�張顒佹惙娴f粣绱濋崡纭僽sh,pop,peek,isEmpty閿涳拷閸欘垯浜掓担璺ㄦ暏閸欙箑顦绘稉锟介嚋閺嶅牊娼垫潏鍛И
*
* @param o
*/
public static void remove(Stack s,Object o) {
if(s == null || s.isEmpty()){
return;
}
Stack tmpStack = new Stack();
while(!s.isEmpty()){
Object value = s.pop();
if(!value.equals(o)){
tmpStack.push(value);
}
}
while(!tmpStack.isEmpty()){
s.push(tmpStack.pop());
}
}

/**
* 娴犲孩鐖ゆい璺哄絿瀵版en娑擃亜鍘撶槐锟�閸樼喐娼甸惃鍕垽娑擃厼鍘撶槐鐘辩箽閹镐椒绗夐崣锟� * 濞夈劍鍓伴敍姘涧閼虫垝濞囬悽鈯縯ack閻ㄥ嫬鐔�張顒佹惙娴f粣绱濋崡纭僽sh,pop,peek,isEmpty閿涳拷閸欘垯浜掓担璺ㄦ暏閸欙箑顦绘稉锟介嚋閺嶅牊娼垫潏鍛И
* @param len
* @return
*/
public static Object[] getTop(Stack s,int len) {
if(s == null || s.isEmpty() || s.size()<len || len <=0 ){
return null;
}
Stack tmpStack = new Stack();
int i = 0;
Object[] result = new Object[len];
while(!s.isEmpty()){
Object value = s.pop();
tmpStack.push(value);
result[i++] = value;
if(i == len){
break;
}
}
return result;
}
/**
* 鐎涙顑佹稉鐬�閸欘垵鍏橀崠鍛儓鏉╂瑤绨虹�妤冾儊閿涳拷 ( ) [ ] { }, a,b,c... x,yz
* 娴h法鏁ら崼鍡樼垽濡拷鐓$�妤冾儊娑撶灚娑擃厾娈戦幏顒�娇閺勵垯绗夐弰顖涘灇鐎电懓鍤悳鎵畱閵嗭拷
* 娓氬顩 = "([e{d}f])" , 閸掓瑨顕氱�妤冾儊娑撹弓鑵戦惃鍕閸欓攱妲搁幋鎰嚠閸戣櫣骞囬敍锟界拠銉︽煙濞夋洝绻戦崶鐎焤ue
* 婵″倹鐏�s = "([b{x]y})", 閸掓瑨顕氱�妤冾儊娑撹弓鑵戦惃鍕閸欒渹绗夐弰顖涘灇鐎电懓鍤悳鎵畱閿涳拷鐠囥儲鏌熷▔鏇$箲閸ョ�alse;
* @param s
* @return
*/
public static boolean isValidPairs(String s){
Stack<Character> stack = new Stack();
for(int i=0;i<s.length();i++){
char c = s.charAt(i);
if(c == '(' || c =='[' || c == '{'){
stack.push(c);
} else if( c == ')'){
char topChar = stack.pop();
if(topChar != '('){
return false;
}
} else if( c == ']'){
char topChar = stack.pop();
if(topChar != '['){
return false;
}
} else if( c == '}'){
char topChar = stack.pop();
if(topChar != '{'){
return false;
}
}
}
return stack.size() == 0;
}
}
Loading

0 comments on commit 9562cee

Please sign in to comment.