Skip to content

Instantly share code, notes, and snippets.

View OMGZui's full-sized avatar
:octocat:
Focusing

omgzui OMGZui

:octocat:
Focusing
  • DXY
  • HangZhou, China
View GitHub Profile
@OMGZui
OMGZui / 3.js
Created October 21, 2022 12:58
class Observer {
constructor (fn) {
this.update = fn;
}
}
class Subject {
constructor() {
this.observers = [];
}
addObserver(observer) {
@OMGZui
OMGZui / 2.js
Created October 21, 2022 12:56
class User {
constructor(name, auth) {
this.name = name
this.auth = auth
}
}
class UserFactory {
static createUser(name, auth) {
if(auth === 'admin') new User(name, 1)
@OMGZui
OMGZui / 1.js
Last active October 21, 2022 12:55
class SingletonLogin {
constructor(name,password){
this.name = name;
this.password = password;
}
static getInstance(name,password){
if(!this.instance)this.instance = new SingletonLogin(name,password);
return this.instance;
}
}
@OMGZui
OMGZui / 6.js
Created October 20, 2022 13:28
const heapSort = array => {
for (let i = Math.floor(array.length / 2 - 1); i >= 0; i--) {
heapify(array, i, array.length);
}
for (let i = Math.floor(array.length - 1); i > 0; i--) {
swap(array, 0, i);
heapify(array, 0, i);
}
return array;
};
@OMGZui
OMGZui / 5.js
Created October 20, 2022 13:27
function mergeSort(arr) {
if(arr.length <= 1) return arr;
const midIndex = arr.length/2 | 0;
const leftArr = arr.slice(0, midIndex);
const rightArr = arr.slice(midIndex, arr.length);
return merge(mergeSort(leftArr), mergeSort(rightArr));
}
function merge(leftArr, rightArr) {
const result = [];
@OMGZui
OMGZui / 4.js
Created October 20, 2022 13:26
function quickSort(arr, left, right) {
if (left < right) {
let pos = left - 1;
for(let i = left; i <= right; i++) {
let pivot = arr[right];
pos++;
let temp = arr[pos];
arr[pos] = arr[i];
arr[i] = temp;
}
@OMGZui
OMGZui / 3.js
Created October 20, 2022 13:23
function quickSort(arr) {
if(arr.length <= 1) return arr;
const pivot = arr.length / 2 | 0;
const pivotValue = arr.splice(pivot, 1)[0];
const leftArr = [];
const rightArr = [];
arr.forEach(val => {
val > pivotValue ? rightArr.push(val) : leftArr.push(val);
})
return [ ...quickSort(leftArr), pivotValue, ...quickSort(rightArr)];
@OMGZui
OMGZui / 2.js
Created October 20, 2022 13:21
function bubbleSort(arr){
for(let i = 0; i < arr.length; i++) {
let flag = true
for(let j = 0; j < arr.length - i - 1; j++) {
if(arr[j] > arr[j+1]) {
flag = false
let temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
}
@OMGZui
OMGZui / 1.js
Created October 20, 2022 13:19
function bubbleSort(arr){
for(let i = 0; i < arr.length; i++) {
for(let j = 0; j < arr.length - i - 1; j++) {
if(arr[j] > arr[j+1]) {
let temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
}
}
}
public class StudentTest {
@Test
public void test(){
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Student student = (Student) context.getBean("student");
System.out.println(student.getName());
}
}