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

update #46

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
52290c9
Merge pull request #1 from guodongym/master
a320321wb Feb 26, 2017
6bf56f4
Amend local
onlyLYJ Feb 26, 2017
5f23dd8
作业
bate999999999 Feb 26, 2017
9c41d74
homework
ls00002 Feb 26, 2017
f887cd1
Merge remote-tracking branch 'refs/remotes/guodongym/master'
zjhylove Feb 27, 2017
788a906
Merge pull request #16 from ls00002/master
guodongym Feb 27, 2017
e0bd349
Merge pull request #15 from bate999999999/master
guodongym Feb 27, 2017
837cc72
Merge pull request #17 from onlyliuxin/master
guodongym Feb 27, 2017
2ef160a
2-26作业
zjhylove Feb 27, 2017
7e60614
读取xml
zjhylove Feb 27, 2017
0a2e978
new Exs
onlyLYJ Feb 27, 2017
73ca231
homework1
Feb 27, 2017
84e3822
struts
zjhylove Feb 27, 2017
8eaa97a
修改View类
zjhylove Feb 27, 2017
cbf8ec8
Array Ex & Test
onlyLYJ Feb 27, 2017
c3cdc41
Merge remote-tracking branch 'guodongym/master'
gukz Feb 28, 2017
e043bad
删除无用的包名
zjhylove Feb 28, 2017
0414284
添加测试单元
zjhylove Feb 28, 2017
653558d
修改
zjhylove Feb 28, 2017
cd03a32
Merge remote-tracking branch 'refs/remotes/origin/master' into guodon…
zjhylove Feb 28, 2017
83c93c6
Merge remote-tracking branch 'refs/remotes/origin/master'
zjhylove Feb 28, 2017
440391d
Merge remote-tracking branch 'refs/remotes/guodongym/master'
zjhylove Feb 28, 2017
3c371d8
Merge pull request #18 from a320321wb/master
guodongym Feb 28, 2017
8598b0e
修改ArrayList
zjhylove Feb 28, 2017
1e25f0a
ArrayUtil answer and it's Junit Test example
gukz Feb 28, 2017
eb8351a
Array Exs
onlyLYJ Feb 28, 2017
275a504
Merge pull request #20 from onlyLYJ/master
guodongym Feb 28, 2017
f3912f9
Merge pull request #21 from onlyliuxin/master
guodongym Feb 28, 2017
b0bfb33
增加位图法
zjhylove Mar 1, 2017
486b11b
Merge remote-tracking branch 'refs/remotes/origin/master' into guodon…
zjhylove Mar 1, 2017
95f73a6
Merge remote-tracking branch 'refs/remotes/origin/master' into guodon…
zjhylove Mar 1, 2017
73ab7c3
Merge remote-tracking branch 'refs/remotes/origin/master' into guodon…
zjhylove Mar 1, 2017
69d3e2b
更改代码
zjhylove Mar 1, 2017
e746e1b
优化
zjhylove Mar 1, 2017
e29c4bb
cafa
zjhylove Mar 2, 2017
a5722d9
优化struts读取xml思路
zjhylove Mar 2, 2017
1a328aa
5commit 5 data struct homework
gukz Mar 2, 2017
dc83eec
优化
zjhylove Mar 3, 2017
3045197
完善
zjhylove Mar 3, 2017
23e6c42
交第二周的作业:模拟strut读取xml
gukz Mar 3, 2017
2995483
some changes to homework1 not important
gukz Mar 3, 2017
99294f2
Merge pull request #25 from GUK0/master
guodongym Mar 3, 2017
0cf43fb
Merge pull request #24 from loveyuanyuanisluckly/master
guodongym Mar 3, 2017
66c131f
del
guodongym Mar 3, 2017
9e6f0cb
maven
guodongym Mar 3, 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
248 changes: 248 additions & 0 deletions group12/2258659044/zj-2017/src/com/coderising/array/ArrayUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
package com.coderising.array;

import com.coding.basic.ArrayList;

public class ArrayUtil {

/**
* 给定一个整形数组a , 对该数组的值进行置换
例如: 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[] temp = new int[length];
for (int i = 0; i < length; i++) {
temp[i] = origin[length-1-i];
}
System.arraycopy(temp, 0, origin, 0, length);
}

/**
* 现在有如下的一个数组: 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[] tempArr = new int[length];
int j = 0;
int zeroNum = 0;//储存0的个数
for (int i = 0; i < length; i++) {
if(oldArray[i]!=0){
tempArr[j] = oldArray[i];
j ++;
}else{
zeroNum ++;
}
}
//删除数组尾端的0
int[] newArray = new int[length-zeroNum];
System.arraycopy(tempArr, 0, newArray, 0, length-zeroNum);
return newArray;
}

/**
* 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
* 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
* @param array1
* @param array2
* @return
*/

public int[] merge(int[] array1, int[] array2){

int length1 = array1.length;
int length2 = array2.length;
int[] array3 = new int[length1 + length2];
//将array1、array2的值加入array3中
System.arraycopy(array1, 0, array3, 0, length1);
System.arraycopy(array2, 0, array3, length1, length2);
int length = array3.length;
int temp;
//将array3冒泡排序
for (int i = 0; i < length; i++) {
for (int j = 0; j < length - i; j++) {
if(array3[i]>array3[j+i]){
temp = array3[i];
array3[i] = array3[j+i];
array3[j+i] = temp;
}
}
}
return duplicate(array3);
}

/**
*去重
*/
private int[] duplicate(int[] array){

for (int i = 1; i < array.length; i++) {
if(array[i-1]==array[i]){
array[i] = 0;
}
}
return removeZero(array);
}

/**
* 位图法合并
* @param array1
* @param array2
* @return
*/
public int[] merge2(int[] array1, int[] array2){

int bitSize = 0;
int a = array1[array1.length-1] ;
int b = array2[array2.length-1];
bitSize =(a>b)?a:b;
boolean[] bitmap = new boolean[bitSize+1];
for (int i = 0; i < array1.length; i++) {
bitmap[array1[i]]=true;
}
for (int i = 0; i < array2.length; i++) {
bitmap[array2[i]]=true;
}

ArrayList ls = new ArrayList();
for (int i = 0; i < bitmap.length; i++) {
if(bitmap[i]==true){
ls.add(i);
}
}
return objList2int(ls);
}

/**
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
* 注意,老数组的元素在新数组中需要保持
* 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
* [2,3,6,0,0,0]
* @param oldArray
* @param size
* @return
*/
public int[] grow(int [] oldArray, int size){

int[] newArray = new int[oldArray.length+size];
System.arraycopy(oldArray, 0,newArray , 0, oldArray.length);
return newArray;
}

/**
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
* 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
* max = 1, 则返回空数组 []
* @param max
* @return
*/
public int[] fibonacci(int max){

int[] array = {};
if(max <= 1)return array;
//生成 斐波那契数列的ArrayList集合
ArrayList ls = new ArrayList();
ls.add(1);ls.add(1);
int next;int i = 1;
while(true){
next = (int)ls.get(i) +(int)ls.get(i-1);
if(next >= max){
break;
}
ls.add(next);
i ++;
}
return objList2int(ls);
}

/**
* 返回小于给定最大值max的所有素数数组
* 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
* @param max
* @return
*/
public int[] getPrimes(int max){

ArrayList primesList = new ArrayList();
boolean flag;
for (int i = 2; i < max; i++) {
flag = false;
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
flag =true;
break;
}
}
if(!flag){
primesList.add(i);
}
}
return objList2int(primesList);
}

/**
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
* 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
* @param max
* @return
*/
public int[] getPerfectNumbers(int max){

int temp;
ArrayList perfectList = new ArrayList();
for (int i = 6; i <= max; i++) {
temp = 0;
for (int j = 1; j <= (i/2); j++) {
if(i%j == 0){
temp += j;
}
}
if(temp == i){
perfectList.add(i);
}
}
return objList2int(perfectList);
}

/**
* 用seperator 把数组 array给连接起来
* 例如array= [3,8,9], seperator = "-"
* 则返回值为"3-8-9"
* @param array
* @param s
* @return
*/
public String join(int[] array, String seperator){

StringBuilder str = new StringBuilder();
for (int i = 0; i < array.length; i++) {
str.append(array[i]+seperator);
}
return str.substring(0, str.lastIndexOf(seperator));
}

/**
* 将存储int数据的ArrayList转换为int数组
* @param ls
* @return
*/
public int[] objList2int(ArrayList ls){

Object[] objArr = ls.toArray();
int[] array = new int[ls.size()];
for (int i = 0; i < ls.size(); i++) {
array[i] = (int) objArr[i];
}
return array;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.coderising.litestruts;

/**
* 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
* @author liuxin
*
*/
public class LoginAction{
private String name ;
private String password;
private String message;

public String getName() {
return name;
}

public String getPassword() {
return password;
}

public String execute(){
if("test".equals(name) && "1234".equals(password)){
this.message = "login successful";
return "success";
}
this.message = "login failed,please check your user/pwd";
return "fail";
}

public void setName(String name){
this.name = name;
}
public void setPassword(String password){
this.password = password;
}
public String getMessage(){
return this.message;
}
}
Loading