-
Notifications
You must be signed in to change notification settings - Fork 2
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
1607094205 冯二燕 #17
Comments
第二次作业 二、简单工厂模式
}
}
}
} 运行结果: 简单工厂模式的优点:工厂类中包含了必要的逻辑判断,根据客户端的选择条件动态实例化相关的类,对于客户端来说,去除了与具体产品的依赖。 简单工厂的缺点:没有遵守开放—封闭原则。所谓的“开放-封闭”原则就是开放接口,封闭修改。如果将来需要添加一个开放的算法,那么,在简单工厂模式中,就必须在简单工厂类中添加相应的判断语句! |
第三次作业 import java.util.HashMap; public class Maptest {
} 运行结果: |
package homework;
import java.util.Scanner;
public class Basesort {
public void sort(int a[]) {
System.out.println("排序算法");
}
class Factory {
private Basesort sort;
public void setsort(Basesort sort) {
this.sort=sort;
}
public void dosort(int a[]) {
sort.sort(a);
}
}
//选择排序
class Selectsort extends Basesort {
public void sort(int a[]) {
int t;
//插入排序
class Insertsort extends Basesort {
public void mian(int a[]) {
int t,j;
for(int i=1;i<a.length;i++) {
t=a[i];
for(j=i-1;j>0&&t<a[j];j--) {
a[j+1]=a[j];
j--;
}
a[j+1]=a[j];
}
}
//快速排序
class Quicksort extends Basesort {
public void swap(int a,int b) {
int t;
t=a;
a=b;
b=t;
}
public void sort(int a[],int left,int right) {
int i = left, j = right;
int t;
t=a[i];
while(i!=j){
while(a[j]<t)
j--;
while(a[i]>t)
i++;
swap(a[i],a[j]);
//测试
class Text2 {
The text was updated successfully, but these errors were encountered: