Skip to content

Instantly share code, notes, and snippets.

@linkkingjay
linkkingjay / t.c
Last active August 29, 2015 14:18
#include <stdio.h>
int x[100001];
int y[100001];
int flag[100001] = {0};
int min(int a, int b) {
return a > b ? b : a;
};
int abs(int x) {
return x > 0 ? x : -x;
function stackseq(input, s, output) {
if (input.length === 0 && s.length === 0) {
console.log(output);
} else {
if (input.length != 0) {
s.push(input.pop());
stackseq(input, s, output);
input.push(s.pop());
}
if (s.length != 0) {
@linkkingjay
linkkingjay / cycle-binary-search.js
Last active August 29, 2015 13:57
循环有序数组的二分查找
/**
* @synopsis 二分法搜索循环有序数组
*
* @param s 要查找的数组
* @param k 要查找的关键字
*
* @returns 当 k 存在时返回 k 的下标,当 k 不存在时返回 -1
*/
var foo = function (s, k) {
var mid;
@linkkingjay
linkkingjay / random_sort.c
Last active December 24, 2015 06:49 — forked from wintercn/adhocSort.js
随机排序,哈哈哈哈。
#include<stdio.h>
#include<stdlib.h>
int is_sorted(int *s, int n) {
int i;
for (i = 0;i < n - 1;i++) {
if (s[i] > s[i + 1])
return 0;
}
return 1;