forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
976 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
group12/247565311/week1/BinaryTreeNode.java → ...65311/structure/week1/BinaryTreeNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package week1; | ||
package structure.week1; | ||
|
||
public class BinaryTreeNode { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
group12/247565311/week1/Iterator.java → ...2/247565311/structure/week1/Iterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
group12/247565311/week1/List.java → group12/247565311/structure/week1/List.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
2 changes: 1 addition & 1 deletion
2
group12/247565311/week1/Queue.java → group12/247565311/structure/week1/Queue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
group12/247565311/week1/Stack.java → group12/247565311/structure/week1/Stack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
group12/247565311/week2/ArrayUtil.java → .../247565311/structure/week2/ArrayUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
group12/247565311/week2/ArrayUtilTest.java → ...565311/structure/week2/ArrayUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
group12/247565311/week3/LinkedList.java → ...247565311/structure/week3/LinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
group12/247565311/week3/LinkedListTest.java → ...65311/structure/week3/LinkedListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package week3; | ||
package structure.week3; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...p12/247565311/week5/LRUPageFrameTest.java → ...311/structure/week5/LRUPageFrameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package week5; | ||
package structure. week5; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.