Skip to content

Commit d23a1fa

Browse files
committed
add
1 parent ad47330 commit d23a1fa

File tree

9 files changed

+134
-60
lines changed

9 files changed

+134
-60
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<className>com.duwei.designpattern.abstractfactory.SpringSkinFactory</className>
4+
</config>

src/com/alibaba/Banker.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55

66
public class Banker{
7-
int available[] = new int[]{3,3,2};//可得到的资源
8-
int max[][] = new int[][]{{7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3}};//每个进程最大资源数
9-
int allocation[][] = new int[][]{{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}};//每个进程目前拥有的资源数
10-
int need[][] = new int[][]{{7,4,3},{1,2,2},{6,0,0},{0,1,1},{4,3,1}};//每个进程需要的资源数
7+
int available[] = new int[]{3,3,2};//可得到的资源
8+
int max[][] = new int[][]{{7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3}};//每个进程最大资源数
9+
int allocation[][] = new int[][]{{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}};//每个进程目前拥有的资源数
10+
int need[][] = new int[][]{{7,4,3},{1,2,2},{6,0,0},{0,1,1},{4,3,1}};//每个进程需要的资源数
1111

12-
void showData()//展示数据输出每个进程的相关数据
12+
void showData()//展示数据输出每个进程的相关数据
1313
{
14-
System.out.println("进程号 Max Allocation Need ");
14+
System.out.println("进程号 Max Allocation Need ");
1515
System.out.println(" A B C A B C A B C");
1616
for(int i = 0;i<5;i++)
1717
{
@@ -23,19 +23,19 @@ public class Banker{
2323
}
2424
}
2525

26-
boolean change(int inRequestNum,int inRequest[]){//分配数据
26+
boolean change(int inRequestNum,int inRequest[]){//分配数据
2727
int requestNum = inRequestNum;
2828
int request[] = inRequest;
29-
// for(int i=0;i<3;i++)System.out.println("修改前available"+available[i]);
29+
// for(int i=0;i<3;i++)System.out.println("修改前available"+available[i]);
3030
if(!(request[0]<=need[requestNum][0]&&request[1]<=need[requestNum][1]&&request[2]<=need[requestNum][2])){
31-
System.out.println("请求的资源数超过了所需要的最大值,分配错误");
31+
System.out.println("请求的资源数超过了所需要的最大值,分配错误");
3232
return false;
3333
}
3434
if((request[0]<=available[0]&&request[1]<=available[1]&&request[2]<=available[2])==false){
35-
System.out.println("尚无足够资源分配,必须等待");
35+
System.out.println("尚无足够资源分配,必须等待");
3636
return false;
3737
}
38-
for(int i = 0;i<3;i++){//试分配数据给请求的线程
38+
for(int i = 0;i<3;i++){//试分配数据给请求的线程
3939

4040
available[i] = available[i]-request[i];
4141

@@ -44,13 +44,13 @@ public class Banker{
4444
need[requestNum][i] = need[requestNum][i] - request[i];
4545

4646
}
47-
boolean flag = checkSafe(available[0],available[1],available[2]);//进行安全性检查并返回是否安全
47+
boolean flag = checkSafe(available[0],available[1],available[2]);//进行安全性检查并返回是否安全
4848

4949
if(flag==true){
50-
System.out.println("能够安全分配");
50+
System.out.println("能够安全分配");
5151
return true;
5252
}else{
53-
System.out.println("不能够安全分配");
53+
System.out.println("不能够安全分配");
5454
for(int i = 0;i<3;i++){
5555
available[i] = available[i]+request[i];
5656
allocation[requestNum][i] = allocation[requestNum][i] - request[i];
@@ -68,15 +68,15 @@ boolean checkSafe(int a,int b,int c){
6868
work[2] = c;
6969
int i=0;
7070
boolean finish[] = new boolean[5];
71-
while(i<5)//寻找一个能够满足的认为完成后才去执行下一进程
71+
while(i<5)//寻找一个能够满足的认为完成后才去执行下一进程
7272
{
73-
if(finish[i]==false&&need[i][0]<=work[0]&&need[i][1]<=work[1]&&need[i][2]<=work[2]){//找到满足的修改work值,然后i=0,重新从开始的为分配的中寻找
74-
System.out.println("分配成功的是"+i);
73+
if(finish[i]==false&&need[i][0]<=work[0]&&need[i][1]<=work[1]&&need[i][2]<=work[2]){//找到满足的修改work值,然后i=0,重新从开始的为分配的中寻找
74+
System.out.println("分配成功的是"+i);
7575
for(int m = 0;m<3;m++)
7676
work[m] =work[m] + allocation[i][m];
7777
finish[i] = true;
7878
i=0;
79-
}else//如果没有找到直接i++
79+
}else//如果没有找到直接i++
8080
i++;
8181
}
8282

@@ -110,29 +110,29 @@ public static void main(String[] args)
110110

111111
String choice = new String();
112112

113-
while(true)//循环进行分配
113+
while(true)//循环进行分配
114114

115115
{
116116

117-
System.out.println("请输入要请求的进程号(0--4):");
117+
System.out.println("请输入要请求的进程号(0--4):");
118118

119119
requestNum = s.nextInt();
120120

121-
System.out.print("请输入请求的资源数目");
121+
System.out.print("请输入请求的资源数目");
122122

123123
for(int i = 0;i<3;i++)
124124

125125
{
126126

127-
System.out.println(source[i]+"资源的数目:");
127+
System.out.println(source[i]+"资源的数目:");
128128

129129
request[i] = s.nextInt();
130130

131131
}
132132

133133
bank.change(requestNum, request);
134134

135-
System.out.println("是否再请求分配(y/n)");
135+
System.out.println("是否再请求分配(y/n)");
136136

137137
choice = s.next();
138138

src/com/alibaba/Test_2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public static void main(String[] args){
77
Integer j = new Integer(3000);
88

99
System.out.println(i == j);
10-
//自动拆箱
10+
//自动拆箱
1111

1212
System.out.println(j.equals(i));
13-
//自动装箱
14-
//Integer的equals方法比较的是值不是地址
15-
//String,Integer,Date在这些类当中equals有其自身的实现,而不再是比较类在堆内存中的存放地址了。
13+
//自动装箱
14+
//Integer的equals方法比较的是值不是地址
15+
//String,Integer,Date在这些类当中equals有其自身的实现,而不再是比较类在堆内存中的存放地址了。
1616
}
1717

1818
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.duwei.lintcode;
2+
3+
4+
import java.util.List;
5+
6+
/**
7+
* 返回二叉树的最大节点
8+
*/
9+
public class MaxNodeInBinaryTree {
10+
11+
TreeNode treeNode = new TreeNode(-100000);//初始值设置极小
12+
13+
public TreeNode maxNode(TreeNode root) {
14+
15+
if (root == null) {
16+
return null;
17+
}
18+
if (root.value > treeNode.value) {
19+
treeNode = root;
20+
}
21+
22+
if (root.left != null) {
23+
maxNode(root.left);
24+
}
25+
26+
if (root.right != null) {
27+
maxNode(root.right);
28+
}
29+
30+
return treeNode;
31+
}
32+
33+
private static class TreeNode {
34+
public int value;
35+
public TreeNode left, right;
36+
37+
public TreeNode(int value) {
38+
this.value = value;
39+
this.left = this.right = null;
40+
}
41+
}
42+
43+
44+
}

src/com/duweri/interview/Sort.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,39 @@ public static void display(int[] arr){
2020
}
2121

2222
/**
23-
* 插入排序
24-
* 关键:1、临时变量保存待排序的数字
25-
* 2、边比较边后移
26-
* 适用情况:序列基本有序的时候
23+
* 插入排序
24+
* 关键:1、临时变量保存待排序的数字
25+
* 2、边比较边后移
26+
* 适用情况:序列基本有序的时候
2727
*/
2828
public static void insertSort(int[] arr){
2929
for (int i = 1; i < arr.length; i++) {
30-
int temp = arr[i];//临时保存待插入序列
31-
int j;//下面先保证J大于0再去访问arr[j]!!!!
32-
for (j = i-1;j >= 0 && temp > arr[j] ; j--) {//带插入序列大于当前序列就前移--》从大到小排列
30+
int temp = arr[i];//临时保存待插入序列
31+
int j;//下面先保证J大于0再去访问arr[j]!!!!
32+
for (j = i-1;j >= 0 && temp > arr[j] ; j--) {//带插入序列大于当前序列就前移--》从大到小排列
3333
arr[j+1] = arr[j];
3434
}
3535
arr[j+1]=temp;
3636
}
3737
}
3838
/**
39-
* 希尔排序
39+
* 希尔排序
4040
*/
4141
public static void shellSort(int[] arr){
4242

43-
for (int i = arr.length/2; i >= 1; i=i/2) {//子序列的划分
43+
for (int i = arr.length/2; i >= 1; i=i/2) {//子序列的划分
4444

4545
}
4646

4747
}
4848
/**
49-
* 冒泡排序
50-
* 关键:1、外循环标识无序区和有序区
51-
* 2、内循环每次将一个无序区的数字排到最前面
49+
* 冒泡排序
50+
* 关键:1、外循环标识无序区和有序区
51+
* 2、内循环每次将一个无序区的数字排到最前面
5252
*/
5353
public static void bubbleSort(int[] arr){
54-
for (int i = 0; i <arr.length-1; i++) {//从后往前推小的
55-
for (int j = arr.length-1; j>i; j--) {//从最后一个开始遍历
54+
for (int i = 0; i <arr.length-1; i++) {//从后往前推小的
55+
for (int j = arr.length-1; j>i; j--) {//从最后一个开始遍历
5656
if (arr[j]>arr[j-1]) {
5757
int temp = arr[j];//swap
5858
arr[j] = arr[j-1];
@@ -63,10 +63,10 @@ public static void bubbleSort(int[] arr){
6363
}
6464

6565
/**
66-
* 快速排序
67-
* 关键: 1、选轴值
68-
* 2、一次划分
69-
* 3、递归快排
66+
* 快速排序
67+
* 关键: 1、选轴值
68+
* 2、一次划分
69+
* 3、递归快排
7070
*/
7171
public static void quickSort(int[] arr,int start,int end){
7272
if(start<end){
@@ -76,12 +76,12 @@ public static void quickSort(int[] arr,int start,int end){
7676
}
7777
}
7878
/**
79-
* 以arr[0]为基准进行一次划分算法,左边都小于arr[0],右边都大于arr[0]
79+
* 以arr[0]为基准进行一次划分算法,左边都小于arr[0],右边都大于arr[0]
8080
*/
8181
private static int partition(int[] arr,int first,int end){
8282

8383
while(first < end){
84-
//先扫描右端
84+
//先扫描右端
8585
while(first < end && arr[first]<arr[end]){
8686
end--;
8787
}
@@ -91,7 +91,7 @@ private static int partition(int[] arr,int first,int end){
9191
arr[first] = temp;
9292
first++;
9393
}
94-
//扫描左边
94+
//扫描左边
9595
while(first < end && arr[first]<arr[end]){
9696
first++;
9797
}
@@ -106,23 +106,23 @@ private static int partition(int[] arr,int first,int end){
106106
}
107107

108108
/**
109-
* 选择排序:
110-
* 每次遍历无序区选出最小的
109+
* 选择排序:
110+
* 每次遍历无序区选出最小的
111111
* @param arr
112112
*/
113113
public static void selectSort(int[] arr){
114114
int minIndex = 0;
115115
for (int i = 0; i < arr.length-1; i++) {
116-
minIndex = i;//指向最小的值的角标
117-
for (int j = i+1; j < arr.length; j++) {//遍历无序区
116+
minIndex = i;//指向最小的值的角标
117+
for (int j = i+1; j < arr.length; j++) {//遍历无序区
118118
if(arr[j] < arr[minIndex]){
119119
minIndex = j;
120120
}
121121
}
122-
if (minIndex != i) { //无序区遍历完了,找到最小的角标了,交换
122+
if (minIndex != i) { //无序区遍历完了,找到最小的角标了,交换
123123
int temp = arr[minIndex];
124124
arr[minIndex] = arr[i];
125-
arr[i] = temp;//把temp放到有序区
125+
arr[i] = temp;//把temp放到有序区
126126
}
127127
}
128128
}

src/com/duweri/interview/string/StringTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.duweri.interview.string;
22
/**
3-
* ×Ö·û´®ÄÚ´æ·ÖÅä
4-
* @author ¶Åΰ
3+
* 字符串内存分配
4+
* @author 杜伟
55
*/
66
public class StringTest {
77

src/com/duweri/interview/string/Test1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ public class Test1 {
44

55
public static void main(String[] args) {
66

7-
String s1="abc"+"def";//1 ³Ø
8-
String s2=new String(s1);//2 ¶Ñ
7+
String s1="abc"+"def";//1
8+
String s2=new String(s1);//2
99
if(s1.equals(s2))//3
1010
System.out.println(".equals succeeded");//4
1111
if(s1==s2)//5 X

src/com/duweri/interview/string/Test2.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ public class Test2 {
66
* @param args
77
*/
88
public static void main(String[] args) {
9-
// TODO Auto-generated method stub
10-
9+
1110
Integer i01=59;
1211
int i02=59;
1312
Integer i03=Integer.valueOf(59);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.duweri.interview.string;
2+
3+
public class Test4 {
4+
5+
public static void main(String[] args) {
6+
Test4.test1();
7+
Test4.test2();
8+
}
9+
10+
private static void test1(){
11+
String s1 ="abc";
12+
String s2 ="a";
13+
String s3 = "bc";
14+
String s4 = s2 + s3;
15+
System.out.println(s1 == s4);
16+
}
17+
18+
19+
private static void test2(){
20+
String s1 ="abc";
21+
final String s2 ="a";
22+
final String s3 = "bc";
23+
String s4 = s2 + s3;
24+
System.out.println(s1 == s4);
25+
}
26+
27+
}

0 commit comments

Comments
 (0)