forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from eloiseSJTU/master
老师的代码
- Loading branch information
Showing
39 changed files
with
1,978 additions
and
49 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
32 changes: 32 additions & 0 deletions
32
group02/562768642/src/com/github/orajavac/coding2017/basic/stack/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.orajavac.coding2017.basic.stack; | ||
|
||
import com.github.orajavac.coding2017.basic.linklist.LRUPageFrame; | ||
|
||
public class Stack { | ||
|
||
private LRUPageFrame l; | ||
|
||
public Stack(int capacity){ | ||
l = new LRUPageFrame(capacity); | ||
} | ||
|
||
public void push(Object o){ | ||
l.addFirst(o); | ||
} | ||
|
||
public String toString(){ | ||
return l.lastToString(); | ||
} | ||
|
||
public Object[] getElements(int len){ | ||
return l.getElements(len); | ||
} | ||
|
||
public void remove(Object obj){ | ||
l.remove(obj, null); | ||
} | ||
|
||
public Object getFirstNode(){ | ||
return l.getFirstNode(); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
group02/562768642/src/com/github/orajavac/coding2017/basic/stack/StackUtil.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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.github.orajavac.coding2017.basic.stack; | ||
|
||
public class StackUtil { | ||
|
||
/** | ||
* 假设栈中的元素是Integer, 从栈顶到栈底是 : 5,4,3,2,1 调用该方法后, 元素次序变为: 1,2,3,4,5 | ||
* 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助 | ||
*/ | ||
public static void reverse(Stack s) { | ||
System.out.println(s.toString()); | ||
} | ||
|
||
/** | ||
* 删除栈中的某个元素 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助 | ||
* | ||
* @param o | ||
*/ | ||
public static void remove(Stack s,Object o) { | ||
s.remove(o); | ||
} | ||
|
||
/** | ||
* 从栈顶取得len个元素, 原来的栈中元素保持不变 | ||
* 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助 | ||
* @param len | ||
* @return | ||
*/ | ||
public static Object[] getTop(Stack s,int len) { | ||
return s.getElements(len); | ||
} | ||
/** | ||
* 字符串s 可能包含这些字符: ( ) [ ] { }, a,b,c... x,yz | ||
* 使用堆栈检查字符串s中的括号是不是成对出现的。 | ||
* 例如s = "([e{d}f])" , 则该字符串中的括号是成对出现, 该方法返回true | ||
* 如果 s = "([b{x]y})", 则该字符串中的括号不是成对出现的, 该方法返回false; | ||
* @param s | ||
* @return | ||
*/ | ||
public static boolean isValidPairs(Stack s,String str){ | ||
for (int i=0;i<str.length();i++){ | ||
char c1 = str.charAt(i); | ||
if(isLeftCase(c1)){ | ||
s.push(c1); //左符号压栈 | ||
}else if (isRightCase(c1)){ | ||
Object obj = s.getFirstNode(); | ||
char[] c = obj.toString().toCharArray(); | ||
if(isCase(c[0],c1)){ //左、右匹配 | ||
s.remove(obj); | ||
}else{ | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* StackUtil 使用 | ||
* @param c1 | ||
* @param c2 | ||
* @return | ||
*/ | ||
public static boolean isCase(char c1,char c2){ | ||
if(c1=='('&&c2==')') | ||
return true; | ||
if(c1=='{'&&c2=='}') | ||
return true; | ||
if(c1=='['&&c2==']') | ||
return true; | ||
return false;//其他的都返回false | ||
}; | ||
|
||
/** | ||
* StackUtil 使用 | ||
* @param c1 | ||
* @return | ||
*/ | ||
public static boolean isLeftCase(char c1){ | ||
if(c1=='(') | ||
return true; | ||
if(c1=='{') | ||
return true; | ||
if(c1=='[') | ||
return true; | ||
return false;//其他的都返回false | ||
}; | ||
|
||
/** | ||
* StackUtil 使用 | ||
* @param c1 | ||
* @return | ||
*/ | ||
public static boolean isRightCase(char c1){ | ||
if(c1==')') | ||
return true; | ||
if(c1=='}') | ||
return true; | ||
if(c1==']') | ||
return true; | ||
return false;//其他的都返回false | ||
}; | ||
} |
24 changes: 24 additions & 0 deletions
24
group02/562768642/src/com/github/orajavac/coding2017/jvm/clz/AccessFlag.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.orajavac.coding2017.jvm.clz; | ||
|
||
public class AccessFlag { | ||
private int flagValue; | ||
|
||
public AccessFlag(int value) { | ||
this.flagValue = value; | ||
} | ||
|
||
public int getFlagValue() { | ||
return flagValue; | ||
} | ||
|
||
public void setFlagValue(int flag) { | ||
this.flagValue = flag; | ||
} | ||
|
||
public boolean isPublicClass(){ | ||
return (this.flagValue & 0x0001) != 0; | ||
} | ||
public boolean isFinalClass(){ | ||
return (this.flagValue & 0x0010) != 0; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
group02/562768642/src/com/github/orajavac/coding2017/jvm/clz/ClassFile.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.github.orajavac.coding2017.jvm.clz; | ||
|
||
import com.github.orajavac.coding2017.jvm.constant.ClassInfo; | ||
import com.github.orajavac.coding2017.jvm.constant.ConstantPool; | ||
|
||
public class ClassFile { | ||
private int minorVersion; | ||
private int majorVersion; | ||
|
||
private AccessFlag accessFlag; | ||
private ClassIndex clzIndex; | ||
private ConstantPool pool; | ||
|
||
|
||
public ClassIndex getClzIndex() { | ||
return clzIndex; | ||
} | ||
public AccessFlag getAccessFlag() { | ||
return accessFlag; | ||
} | ||
public void setAccessFlag(AccessFlag accessFlag) { | ||
this.accessFlag = accessFlag; | ||
} | ||
|
||
|
||
|
||
public ConstantPool getConstantPool() { | ||
return pool; | ||
} | ||
public int getMinorVersion() { | ||
return minorVersion; | ||
} | ||
public void setMinorVersion(int minorVersion) { | ||
this.minorVersion = minorVersion; | ||
} | ||
public int getMajorVersion() { | ||
return majorVersion; | ||
} | ||
public void setMajorVersion(int majorVersion) { | ||
this.majorVersion = majorVersion; | ||
} | ||
public void setConstPool(ConstantPool pool) { | ||
this.pool = pool; | ||
|
||
} | ||
public void setClassIndex(ClassIndex clzIndex) { | ||
this.clzIndex = clzIndex; | ||
} | ||
|
||
|
||
|
||
|
||
public void print(){ | ||
|
||
if(this.accessFlag.isPublicClass()){ | ||
System.out.println("Access flag : public "); | ||
} | ||
System.out.println("Class Name:"+ getClassName()); | ||
|
||
System.out.println("Super Class Name:"+ getSuperClassName()); | ||
|
||
|
||
} | ||
|
||
private String getClassName(){ | ||
int thisClassIndex = this.clzIndex.getThisClassIndex(); | ||
ClassInfo thisClass = (ClassInfo)this.getConstantPool().getConstantInfo(thisClassIndex); | ||
return thisClass.getClassName(); | ||
} | ||
private String getSuperClassName(){ | ||
ClassInfo superClass = (ClassInfo)this.getConstantPool().getConstantInfo(this.clzIndex.getSuperClassIndex()); | ||
return superClass.getClassName(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
group02/562768642/src/com/github/orajavac/coding2017/jvm/clz/ClassIndex.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.orajavac.coding2017.jvm.clz; | ||
|
||
public class ClassIndex { | ||
private int thisClassIndex; | ||
private int superClassIndex; | ||
|
||
public int getThisClassIndex() { | ||
return thisClassIndex; | ||
} | ||
public void setThisClassIndex(int thisClassIndex) { | ||
this.thisClassIndex = thisClassIndex; | ||
} | ||
public int getSuperClassIndex() { | ||
return superClassIndex; | ||
} | ||
public void setSuperClassIndex(int superClassIndex) { | ||
this.superClassIndex = superClassIndex; | ||
} | ||
} |
Oops, something went wrong.