diff --git a/group22/1014331282/Mywork_LX/.classpath b/group22/1014331282/Mywork_LX/.classpath new file mode 100644 index 0000000000..373dce4005 --- /dev/null +++ b/group22/1014331282/Mywork_LX/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/group22/1014331282/Mywork_LX/.project b/group22/1014331282/Mywork_LX/.project new file mode 100644 index 0000000000..1290d27942 --- /dev/null +++ b/group22/1014331282/Mywork_LX/.project @@ -0,0 +1,17 @@ + + + Mywork_LX + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group22/1014331282/Mywork_LX/.settings/org.eclipse.jdt.core.prefs b/group22/1014331282/Mywork_LX/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..3a21537071 --- /dev/null +++ b/group22/1014331282/Mywork_LX/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java b/group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java new file mode 100644 index 0000000000..5446c9b557 --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java @@ -0,0 +1,114 @@ +package week1_0306; + + + +public class ArrayList implements List +{ + + private int size; + + private Object[] elementData ; + + public ArrayList() + { + elementData = new Object[3]; + size=-1; + } + + public void add(Object o) + { + if(size >= elementData.length-1) + { + Object[] replaceData=new Object[elementData.length+5]; + System.arraycopy(elementData, 0, replaceData, 0, elementData.length); + elementData = replaceData; + } + elementData[++size] = o; + } + + public void add(int index, Object o) + { + Object[] replaceData=new Object[11]; + for(int i=0;i=0 && size>=0) + return elementData[index]; + else return null; + } + + + public Object remove(int index) + { + size--; + Object o=elementData[index]; + if (index0) + { + for(int i=index;i=0) + return size+1; + else + return 0; + } + + public Iterator iterator() + { + return new ArrayListIterator(this); + } + + private class ArrayListIterator implements Iterator + { + ArrayList l=null; + int pos = 0; + private ArrayListIterator(ArrayList l) + { + this.l=l; + } + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + pos++; + if(pos > size) + return false; + else return true; + } + + @Override + public Object next() { + // TODO Auto-generated method stub + return elementData[pos]; + + } + + public Object remove() + { + return this.l.remove(pos); + } + + } + +} diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java b/group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java new file mode 100644 index 0000000000..e5b23d37ce --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java @@ -0,0 +1,135 @@ +package week1_0306; + +import java.util.Comparator; + +import week1_0306.BinaryTree.BinaryTreeNode; + +public class BinaryTree +{ + private BinaryTreeNode root; + + private BinaryTreeNode pointer; + + public BinaryTreeNode getRoot() { + return root; + } + + public void setRoot(BinaryTreeNode root) { + this.root = root; + } + + public BinaryTreeNode getPointer() { + return pointer; + } + + public void setPointer(BinaryTreeNode pointer) { + this.pointer = pointer; + } + + public BinaryTree() + { + root=new BinaryTreeNode(); + pointer=root; + } + + public BinaryTreeNode insert(Object o,Comparator c) + { + + pointer= root.insert(o, c); + return pointer; + } + + public void printTree() + { + root.printNode(); + } + + public class BinaryTreeNode + { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public BinaryTreeNode getLeft() { + pointer=left; + return left; + } + + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + + public BinaryTreeNode getRight() { + pointer=right; + return right; + } + + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + + + public BinaryTreeNode insert(Object o, Comparator c) //建有规律的树+插入 + { + if(this.data == null) + { + this.data = o; + return this; + } + + int i = c.compare(this.data,o); + + if( i > 0 ) + { + if(this.left == null) + { + this.left=new BinaryTreeNode(); + this.left.data=o; + return this.left; + } + else + return this.left.insert(o, c); + } + else if(i < 0) + { + if(this.right == null) + { + this.right=new BinaryTreeNode(); + this.right.data = o; + return this.right; + } + + else + return this.right.insert(o, c); + } + else + { + return this; + } + + } + + public void printNode() + { + ScoreRecord s=(ScoreRecord)(this.getData()); + System.out.println(s.getName()+" "+s.getId()); + if(this.getLeft()!=null) + this.getLeft().printNode(); + if(this.getRight()!=null) + this.getRight().printNode(); + else return; + } + + } + +} diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java b/group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java new file mode 100644 index 0000000000..26471af1cd --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java @@ -0,0 +1,9 @@ +package week1_0306; + +public interface Iterator { + + public boolean hasNext(); + public Object next(); + public Object remove(); + +} diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java b/group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java new file mode 100644 index 0000000000..e540a7c115 --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java @@ -0,0 +1,181 @@ +package week1_0306; + + + +public class LinkedList implements List +{ + private Node head; + + private static int size = 0; + + public LinkedList() + { + head=new Node(); + + } + + + private static class Node + { + Object data; + Node next; + } + + public void add(Object o) + { + Node h = head; + while(h.next!= null) + { + h=h.next; + } + Node p = new Node(); + p.data=o; + p.next=null; + h.next= p; + + size++; + } + + public void add(int index, Object o) + { + Node h=head.next; + int i=0; + while(i size) + return false; + else return true; + } + + @Override + public Object next() { + // TODO Auto-generated method stub + return l.get(pos); + + } + + public Object remove() + { + return this.l.remove(pos); + } + + } + + +} + diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/List.java b/group22/1014331282/Mywork_LX/src/week1_0306/List.java new file mode 100644 index 0000000000..7ec758f832 --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/List.java @@ -0,0 +1,18 @@ +package week1_0306; + + + +public interface List { + + public void add(Object o); + + public void add(int index, Object o); + + public Object get(int index); + + public Object remove(int index); + + public int size(); + + public Iterator iterator(); +} diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/Queue.java b/group22/1014331282/Mywork_LX/src/week1_0306/Queue.java new file mode 100644 index 0000000000..e9c32b8e68 --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/Queue.java @@ -0,0 +1,35 @@ +package week1_0306; + +public class Queue { + + private LinkedList queue = new LinkedList(); + + public void enQueue(Object o)//进队列 + { + queue.addFirst(o); + } + + public Object deQueue()//出队列 + { + return queue.removeLast(); + } + + public boolean isEmpty() + { + if(queue.get(0)==null) + return true; + else return false; + } + + public int size() + { + return queue.size(); + } + + public Queue() { + // TODO Auto-generated constructor stub + } + + + +} diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java b/group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java new file mode 100644 index 0000000000..f3bce47950 --- /dev/null +++ b/group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java @@ -0,0 +1,180 @@ +package week1_0306; +/* +提示录入几个学生信息 +录入学号姓名三门成绩 +打印学生中语文数学英语成绩最高的那个人 +统计每门课的平均成绩及总成绩的平均值 +封装处理 +*/ +import java.util.Scanner; +import java.util.Comparator; + +public class ScoreRecord implements Comparator +{ + + private int id; + private String name; + private float C_Score; + private float M_Score; + private float E_Score; + + public ScoreRecord(){}; + + public ScoreRecord(int id,String name,float C_Score, float M_Score, float E_Score) + { + this.id=id; + this.name=name; + this.C_Score=C_Score; + this.E_Score=E_Score; + this.M_Score=M_Score; + } + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public float getC_Score() { + return C_Score; + } + + public void setC_Score(float c_Score) { + C_Score = c_Score; + } + + public float getM_Score() { + return M_Score; + } + + public void setM_Score(float m_Score) { + M_Score = m_Score; + } + + public float getE_Score() { + return E_Score; + } + + public void setE_Score(float e_Score) { + E_Score = e_Score; + } + + public int compare(Object o1, Object o2) + { + ScoreRecord s1 = (ScoreRecord) o1; + ScoreRecord s2 = (ScoreRecord) o2; + if(s1.id>s2.id) + return 1; + else if(s1.id==s2.id) + return 0; + else + return -1; + } + + public int compareTo(Object o1) + { + ScoreRecord s = (ScoreRecord) o1; + if(this.id>s.id) + return 1; + else if(this.id==s.id) + return 0; + else return -1; + } + + public static void readData(ScoreRecord[] arr) + { + Scanner a=new Scanner(System.in); + for(int i=0;i7->10 , 閫嗙疆鍚庡彉涓 10->7->3 + */ + public void reverse(){ + + } + + /** + * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒 + * 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8 + * 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫间负7,8,10 + + */ + public void removeFirstHalf(){ + + } + + /** + * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮 + * @param i + * @param length + */ + public void remove(int i, int length){ + + } + /** + * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁 + * 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱 + * 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601] + * @param list + */ + public static int[] getElements(LinkedList list){ + return null; + } + + /** + * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩 + * 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌 + + * @param list + */ + + public void subtract(LinkedList list){ + + } + + /** + * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩 + * 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級 + */ + public void removeDuplicateValues(){ + + } + + /** + * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩 + * 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛 + * @param min + * @param max + */ + public void removeRange(int min, int max){ + + } + + /** + * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級 + * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪 + * @param list + */ + public LinkedList intersection( LinkedList list){ + return null; + } +} + + \ No newline at end of file diff --git a/group22/1158477486/src/TestCollection/List.java b/group22/1158477486/src/TestCollection/List.java new file mode 100644 index 0000000000..1b14c3ebe6 --- /dev/null +++ b/group22/1158477486/src/TestCollection/List.java @@ -0,0 +1,9 @@ +package TestCollection; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group22/1158477486/src/TestCollection/Queue.java b/group22/1158477486/src/TestCollection/Queue.java new file mode 100644 index 0000000000..4699235e98 --- /dev/null +++ b/group22/1158477486/src/TestCollection/Queue.java @@ -0,0 +1,38 @@ +package TestCollection; + + ; + +public class Queue { + private LinkedList list=new LinkedList(); + + public void enQueue(Object o){ + list.addLast ( o) ;//问题用add(index, o)出错 + } + + public Object deQueue(){ + Object o=list.get(1); + list.remove(1); + return o; + } + + public boolean isEmpty(){ + if(list.size()!=0){ + return false;}else + return true; + } + + public int size(){ + return list.size(); + } + public static void main(String[] args) { + Queue q=new Queue(); + q.enQueue("1"); + q.enQueue("2"); + q.enQueue("3"); + System.out.println(q.size()); + Object o=q.deQueue(); + System.out.println(o); + System.out.println(q.size()); + + } +} diff --git a/group22/1158477486/src/TestCollection/Stack.java b/group22/1158477486/src/TestCollection/Stack.java new file mode 100644 index 0000000000..35fdc6f31b --- /dev/null +++ b/group22/1158477486/src/TestCollection/Stack.java @@ -0,0 +1,36 @@ +package TestCollection; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + return elementData.get(elementData.size()-1) ; + } + + public Object peek(){ + elementData.remove(elementData.size()-1); + return elementData.get(elementData.size()-1); + } + public boolean isEmpty(){ + if(elementData.size()!=0){ + return false;} + return true; + } + public int size(){ + return elementData.size(); + } + public static void main(String[] args) { + Stack s=new Stack(); + s.push("111"); + s.push("211"); + s.push("311"); + System.out.println(s.size());//3 + System.out.println(s.pop()); + System.out.println(s.size()); + System.out.println(s.peek()); + System.out.println(s.size()); + }} diff --git a/group22/1258890344/src/com/coderising/array/ArrayUtil.java b/group22/1258890344/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..773b66ffb7 --- /dev/null +++ b/group22/1258890344/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,209 @@ +package com.coderising.array; + +import java.util.Arrays; +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 a = [7, 9 , 30, 3] , 缃崲鍚庝负 [3, 30, 9,7] + 濡傛灉 a = [7, 9, 30, 3, 4] , 缃崲鍚庝负 [4,3, 30 , 9,7] + * @param origin + * @return + */ + public void reverseArray(int[] origin){ + int length=origin.length; + int value=0; + for(int i=0;i<(length/2);i++){ + value=origin[i]; + origin[i]=origin[length-1-i]; + origin[length-1-i]=value; + + } + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} + * 瑕佹眰灏嗕互涓婃暟缁勪腑鍊间负0鐨勯」鍘绘帀锛屽皢涓嶄负0鐨勫煎瓨鍏ヤ竴涓柊鐨勬暟缁勶紝鐢熸垚鐨勬柊鏁扮粍涓猴細 + * {1,3,4,5,6,6,5,4,7,6,7,5} + * @param oldArray + * @return + */ + + public int[] removeZero(int[] oldArray){ + int length=oldArray.length; + int[] newArray = new int[length]; + int j=0; + for(int i=0;iarray2[j]){ + for(int k=length1;k>i;k--){ + array3[k]=array3[k-1]; + } + array3[i]=array2[j]; + j++; + if(j1){ + array[0]=1; + array[1]=1; + for(int i=2;i>1;i++){ + array[i]=array[i-1]+array[i-2]; + if(array[i]>=max){ + array[i]=0; + return array; + } + } + } + return array; + + + } + + /** + * 杩斿洖灏忎簬缁欏畾鏈澶у糾ax鐨勬墍鏈夌礌鏁版暟缁 + * 渚嬪max = 23, 杩斿洖鐨勬暟缁勪负[2,3,5,7,11,13,17,19] + * @param max + * @return + */ + public int[] getPrimes(int max){ + + int[] array=new int[max]; + int k=0; + if(max==2){ + array[0]=2; + } + for(int i=3;i parameters) { + + /* + + 0. 璇诲彇閰嶇疆鏂囦欢struts.xml + + 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛 + 鎹畃arameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄 + ("name"="test" , "password"="1234") , + 閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶 + + 2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success" + + 3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛, + 閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} , + 鏀惧埌View瀵硅薄鐨刾arameters + + 4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + + */ + View view=new View(); + try { + SAXReader reader=new SAXReader(); + Document doc=reader.read("./src/com/coderising/litestruts/struts.xml"); + Element root=doc.getRootElement(); + List list=root.elements();//灏嗘墍鏈夊厓绱犳斁鍒伴泦鍚堜腑 + List> listMap=getElements(list); + int size=listmap.size(); + listMap.remove(size-1); + System.out.println(listMap.toString()); + + String pathName=""; + int index=0; + String name=parameters.get("name"); + String password=parameters.get("password"); + + Map parameter=new HashMap<>(); + + for(int i=0;i> listmap = new ArrayList>(); + private static Map map=new LinkedHashMap(); + private static List> getElements(List list){ + + for(Iterator itera1=list.iterator();itera1.hasNext();){ + String key=""; + String value=""; + //鑾峰彇action銆乺esult + Element element=itera1.next(); + if(element.getName()=="action"){ + map = new LinkedHashMap(); + } + if(element.getText().trim()!=null){ + value=element.getText(); + } + List attributes=element.attributes(); + + + //鑾峰彇action銆乺esult閲岀殑灞炴у悕鍜屽 + for(Iterator itera2=attributes.iterator();itera2.hasNext();){ + Attribute attr=itera2.next(); + + if(attr.getName().equals("name")){ + key=attr.getValue(); + } + if(attr.getName().equals("class")){ + value=attr.getValue(); + + } + if(!key.trim().isEmpty()&&!value.trim().isEmpty()){ + map.put(key, value); + } + } + + List subList=element.elements(); + //閫掑綊action鐨勭殑瀛愬厓绱犱滑 + if(subList.size()!=0){ + getElements(subList); + } + } + listmap.add(map); + return listmap; + } +} diff --git a/group22/1258890344/src/com/coderising/litestruts/StrutsTest.java b/group22/1258890344/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..ff10b5dd33 --- /dev/null +++ b/group22/1258890344/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,47 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + + + + + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + System.out.println( view.getJsp()); + System.out.println( view.getParameters().get("message")); + +// Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); +// Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + +// System.out.println( view.getJsp()); +// System.out.println( view.getParameters().get("message")); + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group22/1258890344/src/com/coderising/litestruts/View.java b/group22/1258890344/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group22/1258890344/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group22/1258890344/src/com/coderising/litestruts/struts.xml b/group22/1258890344/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..171848ecd1 --- /dev/null +++ b/group22/1258890344/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + diff --git a/group22/17457741/src/ArrayList.java b/group22/17457741/src/ArrayList.java new file mode 100644 index 0000000000..45b583d13c --- /dev/null +++ b/group22/17457741/src/ArrayList.java @@ -0,0 +1,110 @@ +import java.util.Iterator; +import java.util.NoSuchElementException; + +public class ArrayList implements Iterable{ + private static final int CAPACITY = 5; + + private int size; + + private T [] items; + + public ArrayList(){doClear();} + + public void clear(){ + doClear(); + } + + private void doClear(){ + this.size=0;ensureCapacity(CAPACITY); + } + + public int size(){ + return size; + } + + public boolean isEmpty(){ + return size==0; + } + + public void trimToSize(){ + ensureCapacity(size()); + } + + public T get( int a){ + return items[a]; + } + + public T set(int a,T b){ + T old = items[a]; + items[a]=b; + return old; + } + + public void ensureCapacity(int newCapacity){ + if(newCapacitya;i--){ + items[i]=items[i-1]; + } + items[a]=b; + size++; + } + + public T remove(int a){ + T removedItem=items[a]; + for(int i=a;i iterator() { + // TODO Auto-generated method stub + return new ArrayListIterator(); + } + + private class ArrayListIterator implements Iterator{ + + private int current =0; + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + return current implements Iterable{ + private Nodebegin; + private Nodeend; + private int size; + private int modCount=0; + + public LinkedList(){ + doClear(); + } + public void clear(){ + doClear(); + } + private void doClear(){ + begin=new Node(null,null,null); + end=new Node(null,begin,null); + begin.next=end; + } + + public int size(){ + return size; + } + public boolean isEmpty(){ + return size==0; + } + + public boolean add( T x){ + add(size(),x); + return true; + } + public void add(int a,T x){ + addBefore(getNode(a,0,size()),x); + } + + public T get(int a){ + return getNode(a).data; + } + public T set(int a,T newVal){ + Nodep=getNode(a); + T old=p.data; + p.data=newVal; + return old; + } + + public T remove(int a){ + return remove(getNode(a)); + } + + private void addBefore(Nodep,T x){ + Node newNode=new Node<>(x,p.prev,p); + newNode.prev.next=newNode; + p.prev=newNode; + size++; + modCount--; + } + + private T remove(Nodep){ + p.next.prev=p.prev; + p.prev.next=p.next; + size--; + modCount++; + + return p.data; + } + + private NodegetNode(int a){ + return getNode(a,0,size()-1); + } + + private NodegetNode(int a,int lower,int upper){ + Nodep; + + if(aupper) + throw new IndexOutOfBoundsException(); + if(aa;i--) + p=p.prev; + } + return p; + } + @Override + public Iterator iterator() { + // TODO Auto-generated method stub + return new LinkedListIterator(); + } + private class LinkedListIterator implements Iterator{ + private Node current=begin.next; + private int expectedModCount=modCount; + private boolean toRemove=false; + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + return current!=end; + } + @Override + public T next() { + // TODO Auto-generated method stub + if(modCount!=expectedModCount) + throw new java.util.ConcurrentModificationException(); + if(!toRemove) + throw new IllegalStateException(); + + T nextItem=current.data; + current=current.next; + toRemove=true; + return nextItem; + } + + public void remove(){ + if(modCount!=expectedModCount) + throw new java.util.ConcurrentModificationException(); + if(!toRemove) + throw new IllegalStateException(); + + LinkedList.this.remove(current.prev); + expectedModCount++; + toRemove=false; + } + } + + private static class Node{ + + public T data; + public Node prev; + public Node next; + + public Node(T d, Node p,Node n) { + // TODO Auto-generated constructor stub + data=d;prev=p;next=n; + } + + } + +} + diff --git a/group22/17457741/src/Queue.java b/group22/17457741/src/Queue.java new file mode 100644 index 0000000000..b98d8e2043 --- /dev/null +++ b/group22/17457741/src/Queue.java @@ -0,0 +1,29 @@ + + +public class Queue { + + private ArrayList list = new ArrayList(); + + public void enQueue(Object o) { + list.add(o); + } + + public Object deQueue() { + final int size = list.size(); + if (0 == size) + return null; + Object o = list.remove(size); + return o; + } + + public boolean isEmpty() { + return list.isEmpty(); + } + + public int size() { + return list.size(); + } + +} + + diff --git a/group22/17457741/src/Stack.java b/group22/17457741/src/Stack.java new file mode 100644 index 0000000000..12f870566f --- /dev/null +++ b/group22/17457741/src/Stack.java @@ -0,0 +1,33 @@ + + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + + elementData.add(o); + } + + public Object peek(){ + return elementData.get(0); + } + + public Object pop(){ + Object a = null; + if(elementData.size() > 0) { + + a = elementData.get(elementData.size() - 1); + elementData.remove(elementData.size() - 1); + } + return a; + } + + public boolean isEmpty(){ + return elementData.size() == 0; + } + + public int size(){ + return elementData.size(); + } + +} diff --git a/group22/17457741/src/address.txt b/group22/17457741/src/address.txt new file mode 100644 index 0000000000..975ea2b26d --- /dev/null +++ b/group22/17457741/src/address.txt @@ -0,0 +1 @@ + http://www.cnblogs.com/xxp17457741/p/6504673.html \ No newline at end of file diff --git a/group22/910725683/RemoteSystemsTempFiles/.project b/group22/910725683/RemoteSystemsTempFiles/.project new file mode 100644 index 0000000000..5447a64fa9 --- /dev/null +++ b/group22/910725683/RemoteSystemsTempFiles/.project @@ -0,0 +1,12 @@ + + + RemoteSystemsTempFiles + + + + + + + org.eclipse.rse.ui.remoteSystemsTempNature + + diff --git a/group22/910725683/week01/.classpath b/group22/910725683/week01/.classpath new file mode 100644 index 0000000000..1b83178c00 --- /dev/null +++ b/group22/910725683/week01/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/group22/910725683/week01/.gitignore b/group22/910725683/week01/.gitignore new file mode 100644 index 0000000000..6a59c3a991 --- /dev/null +++ b/group22/910725683/week01/.gitignore @@ -0,0 +1,4 @@ +/bin/ +/.settings/ +.classpatch +.prject \ No newline at end of file diff --git a/group22/910725683/week01/.project b/group22/910725683/week01/.project new file mode 100644 index 0000000000..3b3c4fa7ee --- /dev/null +++ b/group22/910725683/week01/.project @@ -0,0 +1,17 @@ + + + week01 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group22/910725683/week01/src/com/coding/basic/ArrayList.java b/group22/910725683/week01/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..acc0e9f8f4 --- /dev/null +++ b/group22/910725683/week01/src/com/coding/basic/ArrayList.java @@ -0,0 +1,98 @@ +package com.coding.basic; +import java.util.Arrays; + +public class ArrayList implements List { + + //数组初始容量// + private final int DEFAULT_CAPICITY=7; + + //数组元素个数// + private int size = 0; + + private Object[] elementData = new Object[DEFAULT_CAPICITY]; + + public void add(Object o){ + ensureCapcity(size+1); + elementData[size++]=o; + } + public void add(int index, Object o){ + //index要连续的增加// + checkIndex(index); + ensureCapcity(size+1); + /* index及后面的元素左移一位,即从index开始移动,注意index从0开始, + * 即还要+1,则长度为size-((index)+1)+1 + */ + System.arraycopy(elementData, index, elementData, index+1, size-index); + elementData[index]=o; + size++; + } + + public Object get(int index){ + checkIndex(index); + return elementData[index]; + } + + public Object remove(int index){ + checkIndex(index); + Object temp=elementData[index]; + /* index后面的元素左移一位,即从index+1开始移动,注意index从0开始, + * 即还要+1,则长度为size-((index+1)+1)+1 + */ + System.arraycopy(elementData, index+1, elementData, index, size-index-1); + size--; + return temp; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return new Iterator(); + } + + private class Iterator{ + private int index=0; + public boolean hasNext(){ + return index=size){ + throw new IndexOutOfBoundsException("get " + index+" in "+size); + } + } + + //判断是否需要扩容并完成扩容// + private void ensureCapcity(int size){ + int oldLength=elementData.length; + if (size>=oldLength){ + //util.ArrayList中的公式,源代码使用的右移1,即除2// + int newLength=oldLength/2+oldLength; + if (newLength7->10 , 逆置后变为 10->7->3 + */ + public void reverse(){ + /*两个指针,开始的时候指向头跟头后面的一个(前指针、后指针) + *循环:每次向后移动步长1,至后指针移到链表尾,size-1个节点需要移动(size-1)-1次 + *先保留前指针的值temp,即当前逆序链表的头,然后再移动前、后指针 + *移动后,将前指针的节点连接到逆序链表的头,开始下一次移动 + *循环结束后,注意到实际重连的只有旧链表的第二个节点到倒数第个节点,需要单独处理旧链表的头尾节点 + *旧链表的尾节点需要链接到逆序链表的头,旧链表的头节点的指针置空,不然会1<->2 + *维护头尾标记 + */ + Node current=head; + Node currentAfter=current.next; + Node temp; + for (int i=0;i5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + */ + public void removeFirstHalf(){ + //int截断,不会有小数// + int removeLength = size / 2; + for (int i=1;i<=removeLength;i++){ + removeFirst(); + } + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * @param i + * @param length + */ + public void remove(int i, int length){ + checkIndex(i); + length=length+i-1; + if (i+length-1>size){ + length=size-i; + } + //从后往前删除,防止越界// + for (int k=length;k>=i;k--){ + remove(k); + } + } + /** + * 假定当前链表和list均包含已升序排列的整数 + * 从当前链表中取出那些list所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * @param list + */ + public int[] getElements(LinkedList list){ + int indexLength=list.size(); + int[] result=new int[indexLength]; + for (int i=0;isize){ + result[i]=0; + }else{ + result[i]=(int)list.get(index); + } + } + return result; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在list中出现的元素 + * @param list + */ + //注意到递增,在外层循环list的时候,保留内层循环的被比较链表的节点的下标并递增即可// + public void subtract(LinkedList list){ + int startIndex=0; + Iterator iter=list.iterator(); + while(iter.hasNext()){ + int src =(int) iter.next(); + while(startIndexmax){ + if (isHeadNoed){ + current=current.next; + removeFirst(); + }else{ + temp.next=current.next; + current=current.next; + size--; + } + }else{ + temp=current; + current=current.next; + isHeadNoed=false; + } + + } + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * @param list + */ + //注意到递增,保留内循环下标位置递增即可// + public LinkedList intersection( LinkedList list){ + LinkedList result = new LinkedList(); + int startIndex = 0; + for (Iterator iter = list.iterator();iter.hasNext();){ + int src = (int) iter.next(); + while (startIndex=size){ + throw new IndexOutOfBoundsException("get " + index+" in "+size); + } + } + + public String toString(){ + StringBuilder sb = new StringBuilder(); + Node current = head; + for (int i=0;i"); + } + current=current.next; + } + return sb.toString(); + } +} \ No newline at end of file diff --git a/group22/910725683/week01/src/com/coding/basic/List.java b/group22/910725683/week01/src/com/coding/basic/List.java new file mode 100644 index 0000000000..29caa79f69 --- /dev/null +++ b/group22/910725683/week01/src/com/coding/basic/List.java @@ -0,0 +1,10 @@ +package com.coding.basic; + + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} \ No newline at end of file diff --git a/group22/910725683/week01/src/com/coding/basic/Queue.java b/group22/910725683/week01/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..6e1b288ebc --- /dev/null +++ b/group22/910725683/week01/src/com/coding/basic/Queue.java @@ -0,0 +1,26 @@ +package com.coding.basic; + +public class Queue { + + private LinkedList queue = new LinkedList(); + + public void enQueue(Object o){ + queue.add(o); + } + + public Object deQueue(){ + return queue.removeFirst(); + } + + public boolean isEmpty(){ + return queue.size()==0; + } + + public int size(){ + return queue.size(); + } + + public String toString() { + return queue.toString(); + } +} \ No newline at end of file diff --git a/group22/910725683/week01/src/com/coding/basic/Stack.java b/group22/910725683/week01/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..a8d071b707 --- /dev/null +++ b/group22/910725683/week01/src/com/coding/basic/Stack.java @@ -0,0 +1,27 @@ +package com.coding.basic; + + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + return elementData.remove(elementData.size()-1); + } + + public Object peek(){ + return elementData.get(elementData.size()-1); + } + public boolean isEmpty(){ + return (elementData.size())==0; + } + public int size(){ + return elementData.size(); + } + public String toString() { + return elementData.toString(); + } +} \ No newline at end of file diff --git a/group22/910725683/week01/test/com/coding/basic/ArrayListTest.java b/group22/910725683/week01/test/com/coding/basic/ArrayListTest.java new file mode 100644 index 0000000000..e0940e8acb --- /dev/null +++ b/group22/910725683/week01/test/com/coding/basic/ArrayListTest.java @@ -0,0 +1,53 @@ +package com.coding.basic; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ArrayListTest { + + ArrayList al = new ArrayList(); + + @Test + public void testAddObject() { + for (int i=1;i<=5;i++){ + al.add(i); + } + } + + @Test + public void testAddIntObject() { + testAddObject(); + al.add(3, 12); + System.out.println("inser index 3 value 12 : "+al.toString()); + } + + @Test + public void testGet() { + testAddObject(); + System.out.println("get index 4 : "+al.get(4)); + } + + @Test + public void testRemove() { + testAddObject(); + System.out.println("remove index 3 : "+al.remove(3)); + } + + @Test + public void testSize() { + testAddObject(); + System.out.println("get size : "+al.size()); + } + + @Test + public void testIterator() { + fail("Not yet implemented"); + } + + @Test + public void testToString() { + fail("Not yet implemented"); + } + +} diff --git a/group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java b/group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java new file mode 100644 index 0000000000..b32b779091 --- /dev/null +++ b/group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java @@ -0,0 +1,47 @@ +package com.coding.basic; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.coding.basic.BinaryTreeNode; + +public class BinaryTreeNodeTest { + + BinaryTreeNode btn = new BinaryTreeNode(); + + @Test + public void testPreOrder() { + testInsert(); + System.out.print("preOrde : "); + btn.preOrder(btn); + System.out.println(""); + } + + @Test + public void testInOrder() { + testInsert(); + System.out.print("inOrder : "); + btn.inOrder(btn); + System.out.println(""); + } + + @Test + public void testPostOrder() { + testInsert(); + System.out.print("postOrder : "); + btn.postOrder(btn); + System.out.println(""); + } + + @Test + public void testInsert() { + btn.insert(45); + btn.insert(24); + btn.insert(53); + btn.insert(12); + btn.insert(37); + btn.insert(93); + } + +} diff --git a/group22/910725683/week01/test/com/coding/basic/LinkedListTest.java b/group22/910725683/week01/test/com/coding/basic/LinkedListTest.java new file mode 100644 index 0000000000..2d22e2e92d --- /dev/null +++ b/group22/910725683/week01/test/com/coding/basic/LinkedListTest.java @@ -0,0 +1,137 @@ +package com.coding.basic; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.coding.basic.LinkedList; + +public class LinkedListTest { + LinkedList ll =new LinkedList(); + @Test + public void testAddObject() { + for (int i=0;i<9;i++){ + ll.add(i); + } + } + + @Test + public void testAddIntObject() { + testAddObject(); + ll.add(4, 22); + ll.add(0, 23); + System.out.println("add int : " + ll.toString()); + } + + @Test + public void testGet() { + testAddObject(); + System.out.println("get index 3 : "+ll.get(3)); + } + + @Test + public void testRemoveInt() { + testAddObject(); + System.out.println("remove index 5 : "+ll.get(5)); + } + + @Test + public void testSize() { + testAddObject(); + System.out.println("get size : "+ll.size()); + } + + @Test + public void testAddFirst() { + testAddObject(); + ll.addFirst(12); + System.out.println("add first : "+ll.toString()); + } + + @Test + public void testAddLast() { + testAddObject(); + ll.addLast(23); + System.out.println("add first : "+ll.toString()); + } + + @Test + public void testRemoveFirst() { + testAddObject(); + ll.removeFirst(); + System.out.println("remove first : "+ll.toString()); + } + + @Test + public void testRemoveLast() { + testAddObject(); + ll.removeLast(); + System.out.println("remove last : "+ll.toString()); + } + + @Test + public void testReverse() { + testAddObject(); + ll.reverse(); + System.out.println("reverse : "+ll.toString()); + } + + @Test + public void testRemoveFirstHalf() { + testAddObject(); + ll.removeFirstHalf(); + System.out.println("remove first half : "+ll.toString()); + } + + @Test + public void testRemoveIntInt() { + testAddObject(); + ll.remove(2, 4); + System.out.println("remove index 2 length 4 : "+ll.toString()); + } + + @Test + public void testGetElements() { + testAddObject(); + System.out.println("get index 2 : "+ll.get(2)); + } + + @Test + public void testSubtract() { + testAddObject(); + LinkedList test1 =new LinkedList(); + for (int i=2;i<5;i++){ + test1.add(i); + } + ll.subtract(test1); + System.out.println("subtract "+test1.toString()+" : "+ll.toString()); + } + + @Test + public void testRemoveDuplicateValues() { + testAddObject(); + for (int i=6;i>2;i--){ + ll.add(i,i); + } + ll.removeDuplicateValues(); + System.out.println("remove dupl : "+ll.toString()); + } + + @Test + public void testRemoveRange() { + testAddObject(); + ll.removeRange(3, 6); + System.out.println("remove range[3,6] : "+ll.toString()); + } + + @Test + public void testIntersection() { + testAddObject(); + LinkedList test2 =new LinkedList(); + for (int i=4;i<14;i=i+2){ + test2.add(i); + } + System.out.println("intersection "+test2.toString()+" : "+ll.intersection(test2)); + } + +} diff --git a/group22/910725683/week01/test/com/coding/basic/QueueTest.java b/group22/910725683/week01/test/com/coding/basic/QueueTest.java new file mode 100644 index 0000000000..18cba75d07 --- /dev/null +++ b/group22/910725683/week01/test/com/coding/basic/QueueTest.java @@ -0,0 +1,40 @@ +package com.coding.basic; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.coding.basic.Queue; + +public class QueueTest { + Queue queue = new Queue(); + + @Test + public void testEnQueue() { + for (int i=0;i<10;i++){ + queue.enQueue(i); + } + } + + @Test + public void testDeQueue() { + testEnQueue(); + for (int i=0;i<3;i++){ + System.out.println("deQueue : " + queue.deQueue()); + } + } + + @Test + public void testIsEmpty() { + System.out.println("is empty(true) : "+queue.isEmpty()); + testEnQueue(); + System.out.println("is empty(false) : "+queue.isEmpty()); + } + + @Test + public void testSize() { + testEnQueue(); + System.out.println("size : "+queue.size()); + } + +} diff --git a/group22/910725683/week01/test/com/coding/basic/StackTest.java b/group22/910725683/week01/test/com/coding/basic/StackTest.java new file mode 100644 index 0000000000..0c8095d79c --- /dev/null +++ b/group22/910725683/week01/test/com/coding/basic/StackTest.java @@ -0,0 +1,48 @@ +package com.coding.basic; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.coding.basic.Stack; + +public class StackTest { + Stack stack = new Stack(); + + @Test + public void testPush() { + for (int i = 0; i < 10; i++) { + stack.push(i); + } + } + + @Test + public void testPop() { + testPush(); + for (int i = 0; i < 3; i++) { + System.out.println("pop : "+stack.pop()); + } + } + + @Test + public void testPeek() { + testPush(); + for (int i = 0; i < 3; i++) { + System.out.println("peek : "+stack.peek()); + } + } + + @Test + public void testIsEmpty() { + System.out.println("is empty(true) : "+stack.isEmpty()); + testPush(); + System.out.println("is empty(false) : "+stack.isEmpty()); + } + + @Test + public void testSize() { + testPush(); + System.out.println("size : "+stack.size()); + } + +}