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;i