Skip to content

Instantly share code, notes, and snippets.

View onlylemi's full-sized avatar

Janbin Qi onlylemi

View GitHub Profile
@onlylemi
onlylemi / SelectSort.java
Created May 27, 2016 04:13
【算法】选择排序
public void sort(int[] arr) {
int min, k;
for (int i = 0; i < arr.length - 1; i++) {
min = arr[i];
k = i;
for (int j = i + 1; j < arr.length; j++) {
if (arr[j] < min) {
k = j;
min = arr[j];
}
@onlylemi
onlylemi / QuickSort.java
Last active May 27, 2016 02:30
【算法】快速排序
private void quickSort(int[] arr, int low, int high) {
if (low < high) {
int first = low;
int last = high;
int key = arr[low];
while (first < last) {
while (first < last && key <= arr[last]) {
last--;
}
// 将比第一个小的放到首端
@onlylemi
onlylemi / shuffle.java
Created May 20, 2016 14:07
【算法】随机排序
/**
* 思想:随机交换
*
* @param arr
*/
public static void shuffle(int[] arr) {
Random r = new Random();
int size = arr.length;
for (int i = size; i > 1; i--) {
int random = r.nextInt(i);
@onlylemi
onlylemi / conn.php
Last active May 19, 2016 23:56
【PHP】连接数据库通用代码
<?php
error_reporting ( 0 );
header ( 'Content-Type:text/html;charset=utf-8' );
// 常量参数
define ( 'DB_HOST', 'localhost' );
define ( 'DB_USER', 'root' );
define ( 'DB_PWD', 'root' );
define ( 'DB_NAME', 'inerd' );