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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

import java.util.Arrays;

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

import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* Created by zhouliang on 2017-03-11.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* 自己实现的BinaryTreeNode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* 自己实现的Iterator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week4.LRU;
package basic.LRU;

/**
* Created by zhouliang on 2017-04-04.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week4.LRU;
package basic.LRU;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week4.LRU;
package basic.LRU;

/**
* Created by zhouliang on 2017-04-04.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* 自己实现的LinkedList
Expand Down Expand Up @@ -228,7 +228,7 @@ public void removeRange(int min, int max){
* 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
* @param list
*/
public LinkedList intersection( LinkedList list){
public LinkedList intersection(LinkedList list){
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* 自己定义的List接口
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* 自己实现的Queue,用自己的LinkedList实现
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

/**
* 自己实现的Stack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week1;
package basic;

import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week2.array;
package basic.array;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week2.array;
package basic.array;

import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.linkedlist;
package basic.linkedlist;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.linkedlist;
package basic.linkedlist;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -8,7 +8,7 @@
*/
public class LinkedListTest {

private week3.linkedlist.LinkedList<Integer> myLinkedList = new week3.linkedlist.LinkedList<>();
private LinkedList<Integer> myLinkedList = new LinkedList<>();

private java.util.LinkedList<Integer> systemLinkedList = new java.util.LinkedList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.linkedlist;
package basic.linkedlist;

/**
* 自己定义的List接口
Expand Down
116 changes: 116 additions & 0 deletions group24/798277403/src/basic/stack/StackUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package basic.stack;

import java.util.Stack;

/**
* Created by zhouliang on 2017-04-08.
*/
class StackUtil {
/**
* 假设栈中的元素是Integer, 从栈顶到栈底是 : 5,4,3,2,1 调用该方法后, 元素次序变为: 1,2,3,4,5
* 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助
*/
public static void reverse(Stack<Integer> s) {
if(s.empty()){
return;
}
int i = getAndRemoveBottom(s); // 依次返回1、2、3
reverse(s);
s.push(i);
}

//移除并返回当前的栈底元素
private static int getAndRemoveBottom(Stack<Integer> s){
int result = s.pop();
if(s.empty()){
return result;
}else{
int bottom = getAndRemoveBottom(s);
s.push(result);
return bottom;
}
}



/**
* 删除栈中的某个元素 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助
* @param o
*/
public static void remove(Stack<Object> s,Object o) {
if(s.empty()){
return;
}
Object temp = s.pop();
if(temp == o){
return;
}
remove(s,o);
s.push(temp);
}

/**
* 从栈顶取得len个元素, 原来的栈中元素保持不变
* 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助
* @param len
* @return
*/
public static Object[] getTop(Stack<Object> s,int len) {
Object[] result = new Object[len];
int index = 0;
while(index<len){
result[index] = getIndex(s,index+1);
index++;
}
return result;
}

//获取第index个元素(从1开始)
private static Object getIndex(Stack<Object> s, int index){
Object temp = s.pop();
index--;
if(0 == index){
s.push(temp);
return temp;
}
Object result = getIndex(s,index);
s.push(temp);
return result;
}


/**
* 字符串s 可能包含这些字符: ( ) [ ] { }, a,b,c... x,yz
* 使用堆栈检查字符串s中的括号是不是成对出现的。
* 例如s = "([e{d}f])" , 则该字符串中的括号是成对出现, 该方法返回true
* 如果 s = "([b{x]y})", 则该字符串中的括号不是成对出现的, 该方法返回false;
* @param s
* @return
*/
public static boolean isValidPairs(String s){
char[] chars = s.toCharArray();
Stack<Character> stack = new Stack<Character>();
for(char c : chars){
if(c=='(' || c=='[' || c=='{'){
stack.push(c);
}else if(c==')'){
char top = stack.peek();
if(top == '('){
stack.pop();
}
}else if(c==']'){
char top = stack.peek();
if(top == '['){
stack.pop();
}
}else if(c=='}'){
char top = stack.peek();
if(top == '{'){
stack.pop();
}
}
}

return stack.empty();
}
}
77 changes: 77 additions & 0 deletions group24/798277403/src/basic/stack/StackUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package basic.stack;

import org.junit.Test;

import java.util.Stack;

/**
* Created by zhouliang on 2017-04-08.
*/
public class StackUtilTest {

@Test
public void testReverse(){
Stack<Integer> s = new Stack<Integer>();
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);
while(!s.isEmpty()){
System.out.println(s.pop());
}
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);
StackUtil.reverse(s);
while(!s.isEmpty()){
System.out.println(s.pop());
}
}

@Test
public void remove(){
Stack<Object> s = new Stack<Object>();
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);

StackUtil.remove(s,3);
while(!s.isEmpty()){
System.out.println(s.pop());
}
}

@Test
public void getTop(){
Stack<Object> s = new Stack<Object>();
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);

Object[] result = StackUtil.getTop(s,2);
while(!s.isEmpty()){
System.out.println(s.pop());
}

for(Object o : result){
System.out.println(o);
}
}

@Test
public void isValidPairs(){
String s = "([e{d}f])";
String s1 = "([b{x]y})";
boolean result = StackUtil.isValidPairs(s);
System.out.println(result);
boolean result1 = StackUtil.isValidPairs(s1);
System.out.println(result1);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package week3;
package download;


import week3.api.Connection;
import download.api.Connection;

import java.io.RandomAccessFile;
import java.util.concurrent.CyclicBarrier;
Expand All @@ -13,7 +13,7 @@ class DownloadThread extends Thread{
private int endPos;
private CyclicBarrier barrier;
private String localFile;
public DownloadThread( Connection conn, int startPos, int endPos, String localFile, CyclicBarrier barrier){
public DownloadThread(Connection conn, int startPos, int endPos, String localFile, CyclicBarrier barrier){

this.conn = conn;
this.startPos = startPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package week3;
package download;


import week3.api.Connection;
import week3.api.ConnectionManager;
import week3.api.DownloadListener;
import download.api.Connection;
import download.api.ConnectionManager;
import download.api.DownloadListener;

import java.io.IOException;
import java.io.RandomAccessFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.api;
package download.api;

import java.io.IOException;

Expand All @@ -9,7 +9,7 @@ public interface Connection {
* @param endPos 结束位置
* @return
*/
public byte[] read(int startPos,int endPos) throws IOException;
public byte[] read(int startPos, int endPos) throws IOException;
/**
* 得到数据内容的长度
* @return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package week3.api;
package download.api;

public class ConnectionException extends Exception {
public ConnectionException(Exception e){
Expand Down
Loading