Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

十四组第一周作业 #25

Merged
merged 31 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4b19a0b
Tennyson's task
Tennysons Feb 24, 2017
07ddfc8
Merge pull request #1 from Tennysons/master
heyucool Feb 24, 2017
29e1c61
作业1-数据结构及文章
BigJoyce Feb 25, 2017
7ce0832
first work
zhanggao Feb 25, 2017
a5a273b
Merge pull request #3 from zhanggao/master
heyucool Feb 25, 2017
26df313
Merge pull request #2 from BigJoyce/master
heyucool Feb 25, 2017
839bda6
BinarySearchTree
Tennysons Feb 25, 2017
37595ce
default
Feb 25, 2017
96dd311
Merge pull request #6 from runMark/master
heyucool Feb 25, 2017
0b3b7ef
README
Tennysons Feb 25, 2017
c28bf65
note link
Tennysons Feb 25, 2017
ac49709
note
Tennysons Feb 25, 2017
aecbf3d
note
Tennysons Feb 25, 2017
a8adc5c
note
Tennysons Feb 25, 2017
33fa8cf
test
Tennysons Feb 26, 2017
60121dc
FirstHomework
MicheyGarcia Feb 26, 2017
0ccb1bf
190530132 submit homework for 20170219
rexwcl Feb 26, 2017
3403990
update the blog linK
rexwcl Feb 26, 2017
496e202
commit 187114392 work
Feb 26, 2017
820adc2
ArrayList,LinkedList,Queue,Stack
zhoubofeng Feb 26, 2017
65b0d9b
Merge pull request #11 from zhoubofeng/master
heyucool Feb 26, 2017
8bc5c8d
Merge pull request #7 from Tennysons/master
heyucool Feb 26, 2017
0d7c19c
Merge pull request #8 from MicheyGarcia/master
heyucool Feb 26, 2017
f0290a2
Merge pull request #9 from rexwcl/master
heyucool Feb 26, 2017
bb45e5a
Merge pull request #10 from posufo/master
heyucool Feb 26, 2017
2169d9f
第一次作业
superfish17 Feb 26, 2017
733e95e
第一周编程作业
Feb 26, 2017
76187af
Merge pull request #12 from superfish17/master
heyucool Feb 26, 2017
2cea31b
first homework
leeyanyang Feb 26, 2017
61d2c9a
fix
leeyanyang Feb 26, 2017
3505a81
Merge pull request #14 from liyanyang0316/master
heyucool Feb 26, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>basicstructuredemo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.maple.basic;

public class ArrayList implements List {

private int size = 0;

private Object[] elementData = new Object[100];

public void add(Object o){
//不够了怎么扩容
elementData[size++]=o;
}
public void add(int index, Object o){
if(index<0||index>size){
throw new IndexOutOfBoundsException("Joy Index "+index+", Size: "+size);
}
for(int i=size;i>index;i--){
elementData[i-1]=elementData[i];
}
elementData[index]=o;
size++;
}

public Object get(int index){
if(index<0||index>=size){
throw new IndexOutOfBoundsException("Joy Index "+index+", Size: "+size);
}
return elementData[index];
}

public Object remove(int index){
if(index<0||index>=size){
throw new IndexOutOfBoundsException("Joy Index "+index+", Size: "+size);
}
Object removeObj=elementData[index];
for(int i=index;i<size-1;i++){
elementData[i]=elementData[i+1];
}
size--;
return removeObj;
}

public int size(){
return size;
}

public Iterator iterator(){
return new Iterator() {
int ref=0;
@Override
public Object next() {
if(hasNext()){
return elementData[ref++];
}
return null;
}

@Override
public boolean hasNext() {
if(ref<0||ref>=size) return false;
return true;
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.maple.basic;

import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;

public class BinaryTree<T extends Comparable<T>> {
private BinaryTreeNode<T> root;

public void traversal(BinaryTreeNode<T> node){
if(node.getLeft()!=null){
traversal(node.getLeft());
}
System.out.println("--"+node.getData()+"--");
if(node.getRight()!=null){
traversal(node.getRight());
}
}
/**
* 如果根节点为null,则作为根节点,否则遍历下去插值
* @param o
* @return
* 2017年2月23日 下午4:21:51
* @Author Joy
*/
public BinaryTreeNode insert(T o){
if(root==null){
BinaryTreeNode<T> newB=new BinaryTreeNode<T>();
newB.setData(o);
newB.setLeft(null);
newB.setRight(null);
root=newB;
return root;
}

return root.insert(o);
}
public BinaryTreeNode<T> getRoot() {
return root;
}

public void setRoot(BinaryTreeNode<T> root) {
this.root = root;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.maple.basic;

import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;

public class BinaryTreeNode<T extends Comparable<T>>{

private T data;
private BinaryTreeNode left;
private BinaryTreeNode right;

/**
* 如果待插入的值等于节点的值,则抛出异常:duplicate value
* 如果小于节点的值,则往左边遍历
* 如果大于节点的值,则往右边遍历
* @param o
* @return
* 2017年2月23日 下午4:22:50
* @Author Joy
*/
public BinaryTreeNode insert(T o){
//assume that no duplicate key

if(o.compareTo(data)==0){
try {
throw new DuplicateName("duplicate value: "+o);
} catch (DuplicateName e) {
e.printStackTrace();
}
}
BinaryTreeNode<T> newB=new BinaryTreeNode<T>();
newB.setData(o);
newB.setLeft(null);
newB.setRight(null);
//o更大,在右边
if(o.compareTo(data)>0){
if(this.getRight()!=null){
this.getRight().insert(o);
}else{
this.setRight(newB);
}
}else if(o.compareTo(data)<0){
if(this.getLeft()!=null){
this.getLeft().insert(o);
}else{
this.setLeft(newB);
}
}
return newB;
}

public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public BinaryTreeNode getLeft() {
return left;
}
public void setLeft(BinaryTreeNode left) {
this.left = left;
}
public BinaryTreeNode getRight() {
return right;
}
public void setRight(BinaryTreeNode right) {
this.right = right;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.maple.basic;

public interface Iterator {
public boolean hasNext();
public Object next();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package com.maple.basic;

import java.util.NoSuchElementException;

public class LinkedList implements List {

private Node head;
private int size = 0;//自己加的,觉得需要
/**
* 与addList()是一样的
*/
public void add(Object o){
addLast(o);
}
public void add(int index , Object o){
if(index<0||index>size){
throw new IndexOutOfBoundsException("Joy Index "+index+", Size: "+size);
}
Node prevNode=head;
Node curNode=head.next;
int count=0;
while(count<=index){
if(count==index){
Node newNode=new Node();
newNode.data=o;

newNode.next=curNode;
prevNode.next=newNode;
size++;
break;
}
curNode=curNode.next;
prevNode=prevNode.next;
count++;
}


}
public Object get(int index){
if(index<0||index>=size)
throw new IndexOutOfBoundsException("Joy Index "+index+", Size: "+size);

Node curNode=head.next;
int count=0;
while(count<=index){
if(count==index){
return curNode.data;
}
curNode=curNode.next;
count++;
}
return null;
}
public Object remove(int index){
if(index<0||index>=size)
throw new IndexOutOfBoundsException("Joy Index "+index+", Size: "+size);
Node prevNode=head;
Node curNode=head.next;
int count=0;
while(count<=index){
if(count==index){
prevNode.next=curNode.next;
size--;
return curNode.data;
}
curNode=curNode.next;
prevNode=prevNode.next;
count++;
}
return null;
}

public int size(){
return size;
}

public void addFirst(Object o){
Node objNode=new Node();
objNode.data=o;
if(head==null) head=new Node();
objNode.next=head.next;
size++;
head.next=objNode;
}
public void addLast(Object o){
Node objNode=new Node();
objNode.data=o;
if(head==null) head=new Node();

//也可以用iterator迭代,先不用吧
Node curNode=head;
while(curNode.next!=null){
curNode=curNode.next;
}
objNode.next=curNode.next;
curNode.next=objNode;
size++;

}
public Object removeFirst(){
if(head==null||head.next==null)
throw new NoSuchElementException();
Node delNode=head.next;
head.next=delNode.next;
size--;
return delNode.data;
}
public Object removeLast(){
if(head==null||head.next==null)
throw new NoSuchElementException();
Node prevNode=head;
Node curNode=head.next;
while(curNode!=null){
if(curNode.next==null){//说明是尾节点
prevNode.next=curNode.next;
size--;
return curNode.data;
}
curNode=curNode.next;
prevNode=prevNode.next;
}
return null;
}
public Iterator iterator(){
return new Iterator() {
private Node cur=head!=null?head.next:head;
@Override
public Object next() {
if(cur==null){
throw new NoSuchElementException();
}
Object object=cur.data;
cur=cur.next;
return object;
}

@Override
public boolean hasNext() {
if(cur==null){
return false;
}else{
return true;
}

}
};
}


private static class Node{
Object data;
Node next;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.maple.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();
}
Loading