必须要会的代码
擅长写bug
专业写bug
展开
-
java单例
Singleton模式的主要作用是保证在Java应用程序中,一个类Class只有一个实例存在。 Singleton模式通常有两种方式。 第一种形式:定义一个类,它的构造函数属于private的,它有一个static的private的该类变量,在类初始化时实例化,通过一个pulbic的getInstance方法获取对对象的引用,继而调用其中的方法。 public class Single原创 2017-01-30 22:40:47 · 186 阅读 · 0 评论 -
冒泡排序法
public class Test { public static void bubbleSort(int[] source) { for(int i=source.length-1;i>0;i--){ for(int j=0;j if(source[j]>source[j+1]){ swap(source,j,j+1); } } } } private static原创 2017-01-31 17:31:10 · 257 阅读 · 0 评论 -
选择排序
package exercise; public class Test { public static void selectSort(int[] source) { for(int i=0;i for(int j=i+1;j if(source[i]>source[j]){ swap(source,i,j); } } } } private static v原创 2017-01-31 17:44:39 · 231 阅读 · 0 评论 -
插入排序
public class Test { public static void insertionSort(int[] source) { for(int i=0;i for(int j=i;j>0;j--){ if(source[j] swap(source,j,j-1); } } } } private static void swap(int[] source, i原创 2017-01-31 19:23:18 · 213 阅读 · 0 评论 -
Shell排序
Shell排序是插入排序的一种。 Shell排序中心思想是将数据进行分组,然后对每一组数据进行排序,在每一组数据都有序后,就可以对所有的分组利用插入排序进行最后一次排序。这样可以显著减少数据交换的次数,以达到加速排序速度的目的。 public class Test { public static void ShellSort(int[] a) { // 将数组分组 for (int r原创 2017-01-31 21:04:16 · 397 阅读 · 0 评论 -
JDBC连接数据库
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DbConn { private static Connection con原创 2017-02-23 17:45:17 · 406 阅读 · 0 评论 -
单链表的反转
public class javaTest1 { public static void main(String[] args) { Node head = new Node(0); Node node1 = new Node(1); Node node2 = new Node(2); Node node3 = new Node(3); Node node4 = new N原创 2017-04-12 15:26:56 · 320 阅读 · 0 评论