自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(64)
  • 收藏
  • 关注

原创 编译期求多个布尔值的与值

编译期求多个布尔值的与值#include <iostream>constexpr auto all() { return true; }template <typename Arg, typename... Rest> requires std::is_same_v<Arg, bool>constexpr auto all(Arg arg, Rest... rest) { return arg && all(rest...); }int

2021-05-24 16:32:55 195

原创 函数参数类型匹配 C++ 实现

函数参数类型匹配 C++ 实现这段代码实现了给定一个函数,函数的参数是否和给定的参数列表匹配以下注释详解实现template <typename Func, typename ... Args>struct is_argument_match{private: // 第一种匹配 // // 匹配一下面的test函数匹配失败的所有情况 template <typename T> static std::false_type test(...); /

2021-05-17 20:12:03 436

原创 寻找数组中第k大元素(C++ 版 )

寻找数组第k大元素和上篇选择排序算法相似,只是分割之后舍弃另一半数据。#include <cassert>#include <iostream>using namespace std;// // 交换 数组中两个元素//void swap(int *data, int a, int b){ int tmp = *(data + a); *(data + a) = *(data + b); *(data + b) = tmp;}////

2021-01-21 10:17:58 1095

原创 快速排序(C++ 版)

#include <iostream>using namespace std;// // 交换 数组中两个元素//void swap(int *data, int a, int b){ int tmp = *(data + a); *(data + a) = *(data + b); *(data + b) = tmp;}//// 对数组区间进行分割,返回支点位置// int partition(int *data, int begin, int

2021-01-20 13:53:54 411

原创 判断一个模板参数是否和之后所有参数类型相同

#include <vector>#include <iostream>#include <type_traits>using namespace std;template<typename T, typename ... Types>struct is_type_all_same;template<typename T, typename T1>struct is_type_all_same<T, T1>{

2021-01-19 11:25:38 222

原创 判断一个模版参数是否在之后的参数列表中

#include <iostream>#include <type_traits>template <typename TargetT, typename ... Ts>struct is_type_in_pack;template <typename TargetT, typename Tt, typename ... Ts>struct is_type_in_pack<TargetT, Tt, Ts...>{ sta..

2020-09-30 14:38:33 154

原创 python with语句简介

在python中读写操作资源,最后需要释放资源。可以使用try…finally结构实现资源的正确释放,python提供了一个with语句能更简便的实现释放资源。1. python像文件的操作open等已经可以直接使用with语句 2. 可以自定义一个支持with语句对象 3. 使用contextlib也可以使用with语句对象 4. 针对需要close操作的对象with的使用示例代码中有4种

2018-04-10 14:26:18 498

原创 python 多线程示例

本文示例描述了两种多线程的方式一种是直接使用threading.Thread(target=func, args=(n,0)一种是继承threading.Thread,实现run成员方法import threadingimport timedef sum(n): sum = 0 for i in range(1, n+1): time.sleep(0.001)

2018-03-01 14:50:17 458

原创 插入排序与快速排序

本文描述了插入排序和快速排序的几种区间划分策咯,参见代码注释import random# 测试数据data = [1,2,3,4,5, 3, 3,6,7,8,9,10,11, 12]# -----------------------------------------------# ---------------- test routine -----------------# -------

2018-02-28 15:51:07 500

原创 数组的旋转

一个含有n个元素的数组向左旋转i次原理描述:假设有一个数组为[ 0 - n ],要向左旋转i次,数组可以被i分割为两部分[ 0 - (i-1) ]和[ i - (n-1) ] 两部分。如果把第一部分[ 0 - (i-1)] 反转变为 [ (i-1) - 0 ], 第二部分[ i - (n-1) ] 反转变为 [ (n-1) - i ],现在数组为[ (i-1) - 0 ] [ (n-1)-i ],继

2018-02-27 15:24:00 903

原创 c++ template 笔记(1) - Policy(一)

# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""class BinaryTree: def __init__(self, value): self._value = value self._parent_node = None s

2018-02-02 14:12:25 372

原创 C语言 extern 数组

在一个文件中定义一个字符数组 (如 char data[100] ),在另一个文件使用extern引用的方式。test.cpp// char data[100] = {10};char data[100] = {0, 0, 0, 0,1};char data[100] = {0, 0, 0, 1};main.cpp#include <iostream>#include <string.h>e

2018-01-31 19:37:58 22828

原创 二叉树搜索求解背包问题

# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""class BinaryTree: def __init__(self, value): self._value = value self._parent_node = None s

2018-01-19 21:56:30 1245

原创 二叉树遍历(DFS和BFS)- python

二叉树的遍历算法 深度优先搜索、广度优先搜索和深度优先搜索返回路径class TreeNode: def __init__(self, value): self._value = value self._parent_node = None self._left_node = None self._right_no

2018-01-19 14:30:04 4241 1

原创 冒泡和插入排序 - python

实现一个类似 python类似sorted函数lst = [2, 3, 6, 3, 10, 4]def bubble_sort(lst, fn = lambda a, b: a > b, asc = False): l = len(lst) for i in range(l): j = 0 while (j 1):

2018-01-16 15:00:51 184

原创 二进制转化到十进制(C++模板)

利用模板方法实现二进制到十进制的转化template <unsigned long N>struct binary{ static unsigned const value = binary<N/10>::value * 2 + N%10;};template <>struct binary<0>{ static unsigned cons

2018-01-04 20:09:22 3322

原创 Singleton Pattern 改进

对上Singleton Pattern的两个改进1. 实例创建条件(instance_ == 0)可能会被编译器优化存储在寄存器中,导致缓存不一致。一个线程对instance的修改没有反映到其他线程的副本中,这样不能防止多次初始化。因此,要使用volatile关键字。2. 每个需要实现Singleton Pattern的类,会有代码冗余,可以使用模板适配需要实现Singleton Pattern的

2018-01-03 13:38:13 189

原创 Singleton Pattern

Singleton Pattern 的两种实现对比Single check 对对象创建锁保护Double check #include <iostream>#include <mutex>#include <chrono>#include <ctime>#define DOUBLE_CHECK (1)using std::chrono::system_clock;us

2018-01-03 10:53:08 243

原创 OS学习笔记(2) - MBR到Loader交接

首先,BIOS加载MBR,我们在MBR中实现对Loader加载到内存一个给定位置(0x900)boot.S%include "boot.inc"SECTION MBR vstart=0x7c00 mov ax, cs mov ds, ax mov es, ax mov ss, ax mov sp, 0x7c00 mov ax, 0xb800

2017-12-20 17:08:47 381

原创 JS学习笔记 - 一个简单例子

获取时间test.html<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <title> Title </title> <script> function displayDate() { document.get

2017-12-20 14:22:24 1272

原创 OS学习笔记(1) - 一个简单的bootsect

使用汇编语言(nasm汇编器)实现一个bootsect,在屏幕上打印一个字符串。 org 07c00h ; BIOS加载bootsect到7c00地址, ; 所以编译第一条指令在7c00位置 ; 取得所在代码段(CS)值,初始化DS和ES,使代码数据指向同一段 mov ax, cs

2017-12-20 13:45:49 279

原创 Swing JTable 简单使用

JTable的使用体现一种MVC的设计模式main.javapackage testtable;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTable;public class KCB { public static void main(String[] args) {

2017-12-19 12:35:33 591

原创 C++ 智能指针简单实现

C++标准库中定义智能指针shared_ptr< T >类型,内部使用了引用计数的方式执行内存的垃圾回收。本文实现一个简单的智能指针,探究内部实现方式。#include <iostream>using namespace std;template <typename T>class SmartPtr;template <typename T>class U_Ptr // 辅助类 {pri

2017-12-18 09:40:54 286

原创 一段有品位的代码

本文源于对一段采访Linux之父的视频,其中李纳斯说的一段链表删除算法是否有品位,补全外围代码,体会大神的品位。看代码~/** * 本文源于对一段采访Linux之父的视频,其中 * 李纳斯说的一段链表删除算法是否有品位, * 补全外围代码,体会大神的品位。 */#include <iostream>#define QUALITY_EDITION struct list_node{

2017-12-14 22:07:08 471

原创 Pygame 学习笔记(4) - 壁球(鼠标版)

壁球游戏加入鼠标控制示例import pygameimport syspygame.init()icon = pygame.image.load('ball.png')pygame.display.set_icon(icon)vInfo = pygame.display.Info()size = width, height = (600, 400)# size = width, heig

2017-12-14 14:41:40 1091

原创 Pygame 学习笔记(3) - 键盘和鼠标事件

pygame 键盘按键示例代码import pygameimport syspygame.init()screen = pygame.display.set_mode((600, 400))pygame.display.set_caption('pygame event')while True: for event in pygame.event.get(): if e

2017-12-14 11:08:22 9591 1

原创 shell 学习笔记(1) - 基础

三种条件判断方式test “$message” = “Hello”[ $message” = “Hello” ][[ $message” == “Hello” ]] bash 内置 (常用)字符串比较 - 条件式str1 == str2str1 != str2-z str1 字符串为空-n str1 字符串不为空str1 == 模式 模式匹配

2017-12-07 11:02:07 259 1

翻译 Pygame 学习笔记(2) - 屏幕模式和窗口标题

pygame 屏幕模式和窗口标题示例代码import pygameimport syspygame.init()icon = pygame.image.load('icon_flower.png')pygame.display.set_icon(icon)vInfo = pygame.display.Info()size = width, height = (600, 400)# siz

2017-12-05 20:48:25 3645

翻译 Pygame学习笔记 (1) - 壁球

Pygame 实现一个壁球小游戏import pygame, sysimport timepygame.init()size = width, heigth = 600, 400speed = [1, 1]BLACK = 0, 0, 0screen = pygame.display.set_mode((600, 400))pygame.display.set_caption('PyGame

2017-12-01 21:45:36 1596

原创 C++ cout输出格式化(1)

如何使用C++输出整数的十六进制形式的字符串。#include <iostream>#include <iomanip> // 操纵器头文件 (IO Manipulators)using namespace std;int main(){ int x = 90; int y = 89; int z = 45; cout << setw(2) << setfill

2017-11-20 15:06:52 498

原创 求一数组前k大的所有数

使用分治和递归算法 - 求数组前k大的所有数(不事先排序)#include <iostream>using namespace std;void PrintArray(int arr[], int s, int e){ for (int i = s; i < e; i++) { cout << arr[i] << ' '; } cout << endl;}

2017-08-18 16:02:21 1132

原创 PyQt5笔记 - CheckBox

本文说明Checkbox的动态创建# -*- coding: utf-8 -*-from PyQt5 import QtCore, QtGui, QtWidgetsclass Widget(QtWidgets.QWidget): def __init__(self): super().__init__() layout = QtWidgets.QVBoxLa

2017-08-05 11:18:17 13119 1

原创 PyQt5笔记 - 状态栏和简单菜单

显示状态栏和菜单import sysfrom PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp #1from PyQt5.QtGui import QIconclass Example(QMainWindow): def __init__(self): super().__init__()

2017-08-04 16:39:29 563

原创 PyQt5笔记 - 消息框和设置窗口中心

消息框import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QMessageBoxclass Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self):

2017-08-04 13:38:49 1961

原创 PyQt5笔记 - 简单例子

一个PyQt窗口简单例子import sysfrom PyQt5.QtWidgets import QApplication, QWidget #1if __name__ == '__main__': app = QApplication(sys.argv) #2 w = QWidget() #3 w.resize(250, 150)

2017-08-04 09:55:36 2442

原创 STL vector的erase方法使用

在stl中vector容器使用中,有时要在for循环中删除多个元素。 如下使用示例:#include <iostream>#include <vector>using namespace std;int main(){ vector<int> vi = {1, 2, 2, 4, 4, 4, 10, 3, 4, 4, 4}; cout << "Erase before >>>" <

2017-07-27 10:55:13 2616

原创 简易计算器(3)- 扩展(支持括号和负数)

继续上文扩展简易计算器,使它支持括号和负数。 修改代码如下: 在TokenKind枚举中加入左右括号的枚举值 lex.h#ifndef _LEX_H#define _LEX_Htypedef enum { TOKEN_BAD, TOKEN_NUM, TOKEN_OP_ADD, TOKEN_OP_SUB, TOKEN_OP_MUL, TOKE

2017-07-26 14:13:06 1274

原创 简易计算器(2)- 语法分析(不使用Yacc)

上文展示了简易计算器的词法分析,获得了表达式中的每个记号。本文继续计算器的语法分析。parser.h#ifndef _PARSER_H#define _PARSER_H#include <stdio.h>#include <stdlib.h>#include "lex.h"#define LINE_BUF_SIZE (1024)double ParseLine();double ParseE

2017-07-25 20:29:24 624

原创 层模式

一个简单例子说明层模式。#include <iostream>using namespace std;class L1Provider{public: virtual void L1Service() = 0;};class L2Provider{public: virtual void L2Service() = 0; void setLowerLayer(L1

2017-07-14 15:09:19 354

原创 体系结构模式

体系结构模式是描述软件系统基本的结构化组织方案,是最高等级模式,明确了一个应用的基本结构。层(Layers)管道和过滤器(Pipes and Filters)黑板(Blackboard)代理模式(Broker模型-视图-控制器(Model-View-Controller)表示-抽象-控制(Presentation-Abstraction-Control)微核(Microkernel)

2017-07-14 15:06:18 1060

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除