准备面试手写了吗(排序算法,设计模式,递归)
public void maoPaoPX ( ) {
int [ ] arr = new int [ ] { 12 , 4 , 54 , 57 , 87 , 3 , 41 , 1 , 3 , 4 , 1 , 3 , 4 , 31 , 2 } ;
for ( int i = 0 ; i < arr. length- 1 ; i++ ) {
for ( int j = 0 ; j < arr. length- 1 - i; j++ ) {
if ( arr[ j] < arr[ j+ 1 ] ) {
int temp = arr[ j] ;
arr[ j] = arr[ j+ 1 ] ;
arr[ j+ 1 ] = temp;
}
}
}
System. out. println ( Arrays. toString ( arr) ) ;
Arrays. sort ( arr) ;
System. out. println ( Arrays. toString ( arr) ) ;
}
public void xuanZePX ( ) {
int [ ] arr= { 1 , 3 , 2 , 45 , 65 , 33 , 12 } ;
for ( int i = 0 ; i < arr. length - 1 ; i++ ) {
int index = i;
int j;
for ( j = i + 1 ; j < arr. length; j++ ) {
if ( arr[ j] < arr[ index] ) {
index = j;
}
}
int tmp = arr[ index] ;
arr[ index] = arr[ i] ;
arr[ i] = tmp;
System. out. println ( Arrays. toString ( arr) ) ;
}
}
public class DiguiTest {
public static void main ( String[ ] args) {
System. out. println ( sumDg ( 100 ) ) ;
}
private static int sumDg ( int i) {
if ( i == 0 ) {
return 0 ;
}
return i+ sumDg ( i- 1 ) ;
}
}
public class Singleton {
private volatile static Singleton instance = null;
private Singleton ( ) { }
public static Singleton getInstance ( ) {
if ( instance == null) {
synchronized ( Singleton. class ) {
if ( instance == null) {
instance = new Singleton ( ) ;
}
}
}
return instance;
}
}