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
#include <iostream> | |
using namespace std; | |
enum PRODUCTTYPE {SFJ, XSL}; // 两种产品:舒肤佳,夏雪莲 | |
// 简单工厂模式 | |
namespace simple_factory { | |
// 抽象基类用首字母小写 | |
class soapBase{ | |
public: | |
virtual ~soapBase(){}; |
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
#include <iostream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
// c语言风格将string转为int, 缺点是不会进行数字检查,遇到非法字符就终止了,直接输出0 | |
void CStyle() { | |
string str = "123s"; | |
int a = atoi(str.c_str()); | |
// 支持多进制转换 |
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
#include <iostream> | |
#include <thread> | |
#include <chrono> // 时间 | |
#include <algorithm> | |
using namespace std; | |
using namespace std::chrono; | |
typedef unsigned long ul; | |
ul OddSum = 0; | |
ul EvenSum = 0; |
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
// | |
// Created by sanjay on 2020/2/21. | |
// | |
#include "NSort.h" | |
void NSort::QuickSort(int *array, int l, int r){ | |
if(l < r) { | |
int i = l, j = r, pivot = array[l]; | |
while (i < 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
#include <iostream> | |
using namespace std; | |
class X {}; | |
class Y : public virtual X {}; | |
class Z : public virtual X {}; | |
class A : public Y, public Z{}; | |
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
#include <iostream> | |
# 学习函数调用的过程和栈帧的理解 | |
# 推荐链接:https://segmentfault.com/a/1190000007977460 | |
int MyFunction(int x, int y, int z) { | |
int a, b, c; | |
a = 10; | |
b = 5; | |
c = 2; |
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
#include <iostream> | |
#include <string> | |
namespace sanjay{ | |
// 写一个简易版哈希表类 | |
class MyHashTable { | |
public: | |
std::string operator[](const std::string& key) const { | |
if(key == key_) { | |
return value_; |
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
#include <iostream> | |
#include <thread> | |
// 这个链接说这样写会产生问题,但是在mac上测试并没有问题 | |
// 链接:https://liam.page/2018/01/18/volatile-in-C-and-Cpp/ | |
namespace sanjay1 { | |
bool flag = false; | |
using Type = int; | |
void test_volatile_demo() { |
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
#include <iostream> | |
#include <vector> | |
/* Copyright sanjay 2020 */ | |
// 本程序使用两种方式实现归并排序,一种是c方式,一种是stl库方式 | |
// 两者差异不大,仅传参类型不一样 | |
namespace c_style { | |
void Merge(int a[], int left, int mid , int right) { | |
// 需要求得每一半的长度,以便申请空间 |
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
#include <iostream> | |
#include <vector> | |
/* Copyright sanjay 2020 */ | |
// 本程序使用两种方式实现归并排序,一种是c方式,一种是stl库方式 | |
// 两者差异不大,仅传参类型不一样 | |
namespace c_style { | |
void Merge(int a[], int left, int mid , int right) { | |
// 需要求得每一半的长度,以便申请空间 |
NewerOlder