Skip to content

Instantly share code, notes, and snippets.

View HongfeiXu's full-sized avatar
🎮
work life balance

凌舟 HongfeiXu

🎮
work life balance
View GitHub Profile
@HongfeiXu
HongfeiXu / MesureTimeExample.cs
Created August 24, 2018 06:27
C# 中,使用 System.Diagnostics.Stopwatch 计时
// https://msdn.microsoft.com/zh-cn/library/system.diagnostics.stopwatch(v=vs.110).aspx
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
// Definition for a binary tree node.
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(nullptr), right(nullptr) { }
};
// 使用先序遍历将二叉树转化为一个字符序列表示的二叉树
void treeToSequence(TreeNode* root, string& result)
{
@HongfeiXu
HongfeiXu / cout_bin_oct_hex.cpp
Last active January 25, 2018 08:42
cout Binary\Octal\Hexadecimal
#include <bitset>
#include <iostream>
using namespace std;
void outbin(const int x) { cout << bitset<sizeof(int) * 8>(x) << endl; } // 二进制输出
void outoct(const int x) { cout << oct << x << endl; } // 八进制输出
void outhex(const int x) { cout << hex << x << endl; } // 十六进制输出
@HongfeiXu
HongfeiXu / Newton_Raphson_method.h
Last active January 21, 2018 09:06
牛顿迭代法快速寻找平方根
#pragma once
/*
牛顿迭代法快速寻找平方根
Ref: https://www.zhihu.com/question/20690553(详细介绍了牛顿-拉弗森方法的原理以及收敛的充分条件)
Ref: http://www.matrix67.com/blog/archives/361
求根号 a,也就是求解 x^2 - a = 0 的非负解。
@HongfeiXu
HongfeiXu / MeasureTime.cpp
Last active January 20, 2018 06:25
使用 C++11 中的 chrono 库 测量时间
/*
时间测量
使用 C++11 中的 chrono 库
http://en.cppreference.com/w/cpp/chrono/duration/duration_cast
*/
#include <chrono>