forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
90a6fb5
commit ea616bc
Showing
15 changed files
with
849 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
.metadata/ | ||
RemoteSystemsTempFiles/ | ||
.recommenders/ | ||
|
||
*.iml | ||
|
||
# Created by https://www.gitignore.io/api/eclipse,intellij,java | ||
|
||
### Eclipse ### | ||
|
||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
.recommenders | ||
|
||
# Eclipse Core | ||
.project | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# PyDev specific (Python IDE for Eclipse) | ||
*.pydevproject | ||
|
||
# CDT-specific (C/C++ Development Tooling) | ||
.cproject | ||
|
||
# JDT-specific (Eclipse Java Development Tools) | ||
.classpath | ||
|
||
# Java annotation processor (APT) | ||
.factorypath | ||
|
||
# PDT-specific (PHP Development Tools) | ||
.buildpath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# Tern plugin | ||
.tern-project | ||
|
||
# TeXlipse plugin | ||
.texlipse | ||
|
||
# STS (Spring Tool Suite) | ||
.springBeans | ||
|
||
# Code Recommenders | ||
.recommenders/ | ||
|
||
### Intellij ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff: | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
*/.idea/ | ||
# Sensitive or high-churn files: | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.xml | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
|
||
# Gradle: | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# Mongo Explorer plugin: | ||
.idea/**/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
### Intellij Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
### Java ### | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# End of https://www.gitignore.io/api/eclipse,intellij,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,6 @@ | ||
.settings/ | ||
/target/ | ||
.classpath | ||
.project | ||
/bin/ | ||
|
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,42 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.dudy</groupId> | ||
<artifactId>learn01</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>learn01</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
|
||
<profiles> | ||
<profile> | ||
<id>jdk-1.8</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
<jdk>1.8</jdk> | ||
</activation> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
124 changes: 124 additions & 0 deletions
124
group04/1796244932/learn01/src/main/java/com/dudy/learn01/base/MyArrayList.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,124 @@ | ||
package com.dudy.learn01.base; | ||
|
||
import java.util.Arrays; | ||
|
||
public class MyArrayList implements MyList { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[16]; | ||
|
||
/** | ||
* 增加元素: ①数组没满之前,直接添加到最后,满了扩容添加 | ||
*/ | ||
public void add(Object o) { | ||
// 检查是否需要扩容 | ||
this.checkGrow(size + 1); | ||
elementData[size++] = o; | ||
} | ||
|
||
/** | ||
* 检查是否需要扩容 | ||
* | ||
* @param newSize | ||
*/ | ||
private void checkGrow(int newSize) { | ||
if (newSize > elementData.length) { | ||
this.grow(elementData); | ||
} | ||
} | ||
|
||
/** | ||
* 扩容 | ||
* | ||
* @param oldElementData | ||
*/ | ||
private void grow(Object[] oldElementData) { | ||
int lenth = (int) (oldElementData.length * 1.5); | ||
elementData = Arrays.copyOf(oldElementData, lenth); | ||
} | ||
|
||
/** | ||
* 根据索引添加:①同 add ② 可能会出现 index 超出当前位置的情况 ③往 中间插入时需要移位 | ||
*/ | ||
public void add(int index, Object o) { | ||
// 检查是否需要扩容 | ||
if (index > size || index < 0) { | ||
throw new RuntimeException("Index: " + index + ", Size: " + size); | ||
} | ||
this.checkGrow(size + 1); | ||
// 循环移位 | ||
int tmp = size; | ||
for (int i = 0; i < size - index; i++) { | ||
elementData[tmp] = elementData[tmp - 1]; | ||
tmp--; | ||
} | ||
// 索引位置赋值 | ||
elementData[index] = o; | ||
size++; | ||
} | ||
|
||
/** | ||
* 直接返回相应数组下标就好 | ||
*/ | ||
public Object get(int index) { | ||
return elementData[index]; | ||
} | ||
|
||
/** | ||
* 删除元素:①注意移位 | ||
*/ | ||
public Object remove(int index) { | ||
// 检查是否需要扩容 | ||
if (index > size || index < 0) { | ||
throw new RuntimeException("Index: " + index + ", Size: " + size); | ||
} | ||
Object desc = elementData[index]; | ||
|
||
for (int i = 0; i < size - index; i++) { | ||
elementData[index] = elementData[index+1]; | ||
index++; | ||
} | ||
size--; | ||
return desc; | ||
} | ||
|
||
public int size() { | ||
return this.size; | ||
} | ||
|
||
public MyIterator iterator() { | ||
|
||
|
||
return new MyItr(); | ||
} | ||
|
||
public class MyItr implements MyIterator{ | ||
|
||
int cursor; | ||
|
||
|
||
|
||
public boolean hasNext() { | ||
return cursor != size; | ||
} | ||
|
||
public Object next() { | ||
|
||
return elementData[cursor++]; | ||
} | ||
} | ||
|
||
|
||
|
||
@Override | ||
public String toString() { | ||
StringBuffer str = new StringBuffer(); | ||
str.append("["); | ||
for (int i = 0; i < size; i++) { | ||
str.append(elementData[i]+","); | ||
} | ||
str.append("]"); | ||
return str.toString(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
group04/1796244932/learn01/src/main/java/com/dudy/learn01/base/MyBinaryTree.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,71 @@ | ||
package com.dudy.learn01.base; | ||
|
||
public class MyBinaryTree { | ||
|
||
private Node root; | ||
|
||
public Node getRoot() { | ||
return root; | ||
} | ||
|
||
static class Node { | ||
private int data; | ||
private Node left; | ||
private Node right; | ||
|
||
public Node(int data) { | ||
this.data = data; | ||
} | ||
|
||
} | ||
|
||
public Node insert(int o) { | ||
Node newNode = new Node(o); | ||
|
||
if (root == null) { | ||
root = newNode; | ||
return newNode; | ||
} | ||
Node currentNode = root; | ||
|
||
while (true) { | ||
// System.out.println("currentNode: " + currentNode.data ); | ||
if (o <= currentNode.data) { // left | ||
|
||
if (currentNode.left != null) { | ||
currentNode = currentNode.left; | ||
} else { | ||
currentNode.left = newNode; | ||
// System.out.println("left return ..."); | ||
// System.out.println(""); | ||
return newNode; | ||
} | ||
} else { // right | ||
if (currentNode.right != null) { | ||
currentNode = currentNode.right; | ||
} else { | ||
currentNode.right = newNode; | ||
// System.out.println("right return ..."); | ||
// System.out.println(""); | ||
return newNode; | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
public void display(Node root) { | ||
|
||
System.out.print(root.data + " "); | ||
if (root.left != null) { | ||
display(root.left); | ||
} | ||
if (root.right != null) { | ||
display(root.right); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
group04/1796244932/learn01/src/main/java/com/dudy/learn01/base/MyIterator.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,6 @@ | ||
package com.dudy.learn01.base; | ||
public interface MyIterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
Oops, something went wrong.