This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Insertion { | |
public static void sort(Comparable[] a) { | |
int N = a.length; | |
// 从第二个元素开始操作 | |
for (int i = 1; i < N; i++) { | |
// 索引之前的所有元素, 从右往左, 一个个进行比较, 如果后一个比前一个小, 则交换相邻的两个元素 | |
for (int j = i; j > 0 && less(a[j], a[j - 1]); j--) { | |
exch(a, j, j-1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Selection { | |
public static void sort(Comparable[] a) { | |
int N = a.length; | |
for (int i = 0; i < N; i++) { | |
int min = i; | |
for (int j = i + 1; j < N; j++) { | |
if (less(a[j], a[min])) { | |
min = j; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('app2.js: 1 -> -> ', 'apps'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script> | |
document.addEventListener('DOMContentLoaded', function (event) { | |
console.log('index.html: 9 -> -> ', 'dom'); | |
console.log('index.html: 10 -> -> ', document.getElementById('img').offsetWidth); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script> | |
document.addEventListener('DOMContentLoaded', function (event) { | |
console.log('index.html: 9 -> -> ', 'dom'); | |
console.log('index.html: 10 -> -> ', document.getElementById('img').offsetWidth); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
</head> | |
<body> | |
<h1>This page does nothing....</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const crypto = require('crypto'); | |
const realm = 'user'; | |
const ACCOUNT = { | |
'username': 'psw' | |
}; | |
class Nonce { | |
constructor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sorting | |
# Implement two types of sorting algorithms: | |
# Merge sort and bubble sort. | |
import math | |
from random import randint | |
def merge_arr(arr1, arr2): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fast Exponentiation | |
# Ask the user to enter 2 integers a and b and output a^b (i.e. pow(a,b)) in O(lg n) time complexity. | |
def my_pow(a, b): | |
if b == 0: return 1 | |
temp = my_pow(a, b // 2) | |
if b % 2 == 0: | |
return temp * temp | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Next Prime Number | |
# Have the program find prime numbers until the user chooses to stop asking for the next one. | |
# 找到下一个质数 | |
prime_number = [2] | |
i = 0 | |
def find_next_prime(): | |
global i |