-
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
1607084207 张阳 #22
Comments
第二次作业单例模式:只能产生一个实例 `package Design.src.People; public class People {
} public class PeopleText {
} ` 为什么有了接口还要使用抽象类1.一个类可以实现多个接口,同时要实现接口里所有的方法,但是一个类只能继承一个类,不能是多继承 |
第三次培训Foreach`package BianLi; import java.util.Collection; public class Foreach {
// for(Object obj:book) } Iterator`package Demo1.src.Collection; public class catSet {
} import java.util.HashSet; public class catSetText {
} lambdapackage BianLi; import java.util.HashSet; public class lambda {
} |
package Sort.src.BaseSort;
public class BaseSort {
public void sort(int []a)
{
System.out.println("排序算法");
}
}
package Sort.src.BaseSort;
public class InsertSort extends BaseSort{
public void sort(int []a,int n)
{
for(int i=0;i<n;i++)
{
for(int j=i;j>0;j--)
{
if(a[j]<a[j-1])
{
swap(a,j,j-1);
}
else
break;
}
}
}
public void swap(int []a,int i,int j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
package Sort.src.BaseSort;
public class QuickSort extends BaseSort{
public int getElem(int []a,int l,int r)
{
int j=l;
for(int i=l+1;i<=r;i++)
{
if(a[i]<a[j])
{
swap(a,j+1,i);
}
}
return j;
}
public void swap(int []a,int i,int j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
public void sort(int []a,int n)
{
int m=getElem(a,0,n-1);
getElem(a,0,m-1);
getElem(a,m+1,n-1);
}
}
package Sort.src.BaseSort;
public class SelectSort extends BaseSort {
public void sort(int []a,int n)
{
for(int i=0;i<n;i++)
{
int min=i;
for(int j=i+1;j<n;j++)
{
if(a[min]>a[j])
{
min=j;
}
}
swap(a,i,min);
}
}
public void swap(int []a,int i,int j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
package Sort.src.BaseSort;
import java.util.Scanner;
public class Text {
public static void main(String[] args) {
int[] a=new int[10];
Scanner scanner=new Scanner(System.in);
for(int i=0;i<10;i++)
{
a[i]=scanner.nextInt();
}
System.out.println("选择排序:");
SelectSort one=new SelectSort();
one.sort(a,10);
for(int i=0;i<10;i++)
{
System.out.print(a[i]+",");
}
System.out.println();
System.out.println("选择排序:");
InsertSort two=new InsertSort();
two.sort(a,10);
for(int i=0;i<10;i++)
{
System.out.print(a[i]+",");
}
System.out.println();
System.out.println("快速排序:");
QuickSort three=new QuickSort();
three.sort(a,10);
for(int i=0;i<10;i++)
{
System.out.print(a[i]+",");
}
System.out.println();
}
}
The text was updated successfully, but these errors were encountered: