自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

qq_31805127的博客

学习使我快乐

  • 博客(58)
  • 收藏
  • 关注

原创 C++多线程-条件竞争笔记

1、先来看一段多线程代码:std::shared_ptr<some_resource> resource_prtr;std::mutex resource_mutex;void foo(){ std::unique_lock<std::mutex> lk(resource_mutex); //此处所有线程序列化 if(!resource_ptr) { resource_ptr.reset(new some_resource);//1,只有初始化过程需要保护

2021-08-08 18:05:47 356 1

原创 C++函数调用运算符

1、在C++中,如果类重载了函数调用运算符,我们可以使用函数一样使用该类对象。由于这种类同时也能够存储状态,所以相比普通函数更加灵活。ex1:struct absInt { int operator() (int val) const { return val <0? -val:val; }}以上类只定义了一种操作,函数调用运算符。使用方法:int i = -42;absInt absObj;int ui = absObj(i); //将i传递给absObj.operat

2021-06-06 11:39:54 353

原创 Go语言接口

1、Go语言的接口是把某些公共函数定义在接口里,其他类型实现了这些方法就是实现了这个接口。/*接口定义*/type interface_name interface{ method_name1 [return_type] method_name2 [return_type]}/*定义结构体*/type struct_name struct {}_ty/*实现接口方法*/func (struct_name_variable struct_name) method_name1() [retu

2021-03-14 22:06:42 105

原创 go语言结构体

1、结构体定义需要用到type和struct语句。type struct_variable_type struct { member definition member definition member definition}变量声明:variable_name := struct_variable_type {value1, value2, value3...}varibale_name := struct_variable_type {key1:value1, key2:valu

2021-03-14 12:16:52 213

原创 go语言指针

1、go取址符为&.var a int = 10fmt.Printf("变量地址:%x\n", &a)2、指针:一个指针变量指向了一个值的内存地址:使用方式: var var_name *var_typevar ip *int /*指向整型*/var fp *float32 /*指向浮点型*/3、如何使用指针1、定义指针变量;2、为指针变量赋值3、访问指针变量中指向的地址var ip *intvar a intip = *&afmt.Pri

2021-03-14 11:12:09 111

原创 go数组初始化

1、数组初始化:`var ba = [5] float32{1000,2,3,7,50}//或者balance:=[5]float32{1000,2,3,7,50}2、如果数组长度不确定,可以使用…代替数组长度。var ba = [...]float32{1000,2,3,7,50}//或者balance := [...]float32{1000,2,3,7,50}3、设置了数组的长度,还可以指定下标来初始化元素,其中初始化数组中{}的元素个数不能大于[]中的数字。balance :=

2021-03-14 10:41:15 1424

原创 C++extern关键字

1、使用extern关键字;参考:https://www.jb51.net/article/160466.htmextern 关键字用于使用外部文件定义的变量;该变量特点:1、需为全局变量;2、在引用时只需要指明类型以及变量名即可,不需要重新赋值。3、不需要改该变量被虚构可以用const关键字修饰;4、用include将另一个文件全部包含进去可以引用另一个文件中的变量,但是这样被包含的变量和方法都可以被这文件使用,会导致不够安全。举例:main.c中声明该变量在别处存在,让编译器去其他地方

2021-02-28 17:46:08 122

原创 vscode设置go跳转

vscode的定义跳转一直不生效,以为是版本的问题。正当我考虑安装哪一个旧版本的vscode,这跳转忽然生效了,真真玄学。 记录一下我今天的操作: 1、文件-首选项-update:Mode:设置为none。 2、 首选项--扩展-go。 Docs tools -->设置为godoc,并取消use language server的选项,会提示安装godef。安装好就可以跳转了,可能是我之前都没有安装godef的插件。 ![use language server](https://img...

2021-01-17 10:51:09 3607 2

原创 go-chan信道用法

接收信道中信息:v,ok := <-ch //通道接收不到数据后,ok便为false,这时候就可以用close()来关闭实例:package mainimport ( "fmt")func fibonacci(n int, c chan int) { x, y := 0, 1 for i := 0; i < n; i++ { c <- x x, y = y, x+y } close(c)}func main() { c := make(chan in

2020-12-20 23:01:50 152

原创 go函数闭包

1、匿名函数:go语言支持匿名函数,可作为闭包。匿名函数是一个内联语句或者表达式,匿名函数的优越性在于可以直接使用函数内的变量。代码如下:package mainimport "fmt"func getSequence() func() int{ i = 0 return func() int { i+=1 return i }}func main(){ //函数i=0 nextNumber := getSequence() //调用nextNumber函数,i变量自增1并返

2020-12-20 22:40:40 172

原创 go函数体定义-函数参数&引用

1、go函数定义格式如下:func function_name([parameter list]) [return_types]{}2、go函数引用传递值:package mainimport “fmt”func main() {var a int = 100var b int = 200//fmt.Println()swap(&a, &b)}func swap(x *int, y *int) { var temp int temp = *x //保持x地址上的

2020-12-20 22:28:19 549

原创 go基础--常量

1、语言常量常量:程序运行时,不会被修改的量const identifier [type] = value;显式 类型定义 const b string = "abc"隐式: const b = "abc"iota: 特殊常量,被认为可被编译器修改的量。在const关键字出现时被重置为0,const中每新增一行便将iota计数一次(iota可以被认为const语句块中的行索引),iota可以被认为是枚举值。const (a = iota//=0b = iota//1c

2020-12-20 21:43:14 45

原创 go函数

1、函数定义:func function_name([parameter list] ) [return types] {函数体}2、变量类型var identifier type如:var a string="Run"var b,c int = 1,2声明方式:1、声明变量类型,如果没有初始化,则默认为零值;var a = "run"var b intvar c bool其中默认值,数值为0,布尔为false,字符串为"",以下几种为nil。var a *intvar

2020-11-16 16:07:58 56

原创 go基础1

1、每个Go应用程序都包含一个名为main的包,main函数是每一个可执行程序所必须包含的,一般来说是启动后第一个执行的函数。2、注释:多行:/**/,单行://。3、.go变量作用域:1、局部变量:函数体之内声明的变量称为局部变量;2、全局变量:函数体之外声明的变量称为全局变量,全局变量可以在整个包甚至外部包(被导出后)使用,全局变量可以在任何函数中使用。不同类型的局部或全局变量默认值为:| 类型 | 初始化默认值 ||int–|0–||-float32-|-0-|| pointer |

2020-11-09 21:06:37 79

原创 lua中的函数--7

1.封闭(Closures)例子如下:根据成绩对名字进行排名,成绩高的在前:names = {"Peter", "Paul", "Mary"}grades = {Mary=10, Paul=7. Peter=8}table.sort(names, function(n1,n2)return grades[n1] > grades[n2] --compare the gradesend) 写成函数:function sortbygrade(names, grades) ta

2020-10-08 18:22:23 86

原创 lua中的函数--6

1.first-classlua中的函数被称为第一类值,也就是函数能够被存储在变量中和表中,也能被当做参数传递,也能够被其它函数返回。其中lua中的函数是没有名字的, 当我们讨论函数的名字,比如print,实际说的是变量(能够实现函数功能的变量)。a = {p = print}a.p("Hello World") -->Hello Worldprint = main.sin -->'print' now refers to the sine functiona.p(pri

2020-10-08 17:50:34 119

原创 lua中的函数--3

1.指定参数的名字--表构造器,()可有可无.rename{old="temp.lua",new="temp1.lua"}如果需要指定参数的名字,可以通过传入表的方式进行传参。function rename(arg) return os.rename(arg.old,arg.new)end另外一个例子:x = Window{x=0,y=0,width=30,height=200,title="Lua",background="blue",border=true}function Win

2020-10-08 17:17:33 97

原创 lua中的函数--2

1.函数的参数数目printResult = ""function print(...) for i, v in ipairs(arg) do printResult = printResult .. tostring(v).."\t" end printResult = printResult .. "\n"end 其中(…)三个点表示可变长度的参数, 当函数调用时,所有参数被转变为一个表,便是隐藏的参数被称作arg。此外arg还包含一个值n,指的是实际传入参数的数目。指定接收参数

2020-10-08 16:51:13 157

原创 lua中的函数--1

参考笔记:ttp://www.lua.org/pil/5.html1.函数调用规则和其他语言一样,调用一般使用括号。print(8*9,9/8)a=math.sin(3) + math.cos(10)print(os.date())需要注意的一点是:如果函数只有一个参数,且改参数是字符串或者表构造器,括号则可有可无。print "Hello World" --> print("Hello World")dofile 'a.lua' -->dofile('a.lua')pr

2020-10-08 16:30:05 205

原创 lua语句结构3--控制结构

1.控制结构if/for/while -----> enduntil -------> repeatlua中除了false和nil之外,其他值均为true。2.if then else其中的else部分可有可无。if a < 0 then a = 0 endif a < b then return a else return b endif line > MAXXLINES then showpage() line = 0end

2020-10-06 17:47:02 106

原创 lua语句结构2--局部变量

1.局部变量以及块(Block)除了全局变量之外,lua语句还支持局部变量,使用(local关键字)。局部变量的作用于局限于他们声明的语句块中:比如函数体,也比如控制语句中,以及chunk(the file or string with the code where the variable is declared)j = 10 --global variablelocal i = 1 ---local variablex = 10 local i = 1 -- local to

2020-10-06 17:16:18 469

原创 lua 语句结构1

1.赋值最基本的赋值操作a = "Hello" .. "world"t.n = t.n+1--多重赋值a, b = 10, 2*xx,y = y, x --swap x and ya[i], a[j] = a[j], a[i] --swap a[i] and a[j]--多重赋值a,b,c = 0, 1 --c将会被赋值为nilprint(a,b,c) --> 0 1 nila,b = a+1, b+1, b+2 -->value of b+2 is ignoredp

2020-10-06 16:50:42 35

原创 lua基础3

1.逻辑运算符and, or , notand:只有第一个参数为false,返回第一个参数;第一个参数为真,返回第二个参数。or:只有第一个参数为true,返回第一个参数;否则,返回第二个参数。--if not x then x=v endx=x or v上述表达式:如果x为false,则x被赋值为v。a and b or c--类似于c语言中的a?b : cmax = (x>y) and x or ynot运算符返回true或者false。print(not nil) --

2020-10-06 16:40:55 79

原创 linux--awk笔记1

刚刚进入工作一个多月了,发现工作环境需要大量使用linux命令,趁着国庆假期补补课。参考: https://awk.readthedocs.io/en/latest/chapter-one.html1.awk程序结构pattern{action}awk的基本操作是一行一行扫描输入,搜索匹配模式的行,执行动作后进行下一行的读取。1) A 数学 802) B 语文 903) C 英语 87对于上述的表数据,$4 == 90 {print $2}将打印出第4个字段为90的名

2020-10-05 18:51:17 507

原创 shell编程笔记1

一、Shell 变量:1.定义变量时,变量名与等号之间不能有空格。your_name="runoob.com"2.除了显式得直接赋值,还可以用语句给变量赋值,for file in `ls /etc`or for file in $(ls /etc)3.使用定义过的变量,需要在变量前加美元符号,如:your_name="qinjx"echo $your_nameecho ${your_name} ```{}帮助判断边界4.只读变量不能修改,也不能删除。myUrl="www.ba

2020-10-04 18:10:45 65

原创 grep命令筛选前后n行

grep -a 'keyword’ -An filename .显示keyword对应行的后5行。grep -a 'keyword’ -Bn filename .显示keyword对应行的前5行。grep -niR -a ‘2020/10/03 16:0[0-1]’ error.log.筛选时间。grep -a ‘-20009’ filename. 筛选含有特殊字符的字符串如’-20009’。grep命令还是强大呀!工欲善其事,必先利其器!...

2020-10-03 22:22:30 1712

原创 lua基础笔记

lua中的代码块被称为chunk。lua中分号可有可无。同一行的多个表达可以使用“;”分开。a = 1b = a*2a = 1;b = a*2;a = 1; b = a*2a = 1 b = a * 2 -- ugly but valid连接两个lua文件的方法:a.lua: x=1b.lua: print(x);命令: lua -la -lb输出: 1还可以使用dofile函数连接代码块。--file 'lib1.lua'function norm(x, y) l

2020-09-30 17:27:46 71

原创 lua基础之lua表结构

lua基础之lua表结构:http://www.lua.org/pil/2.5.html1.在lua中,nil不是0,也不是空字符串"",索引值从1开始。a = {}a["x"] = 10 b = a --"b" refers to the same table as "a"print(b["x"]) ---10print(a["x"]) ---20a = nil --now only "b" refers to the tableb = nil --now ther

2020-09-30 15:49:41 338

原创 在Android Studio中下载Android SDK

看网上说需要设置代理1.修改hosts文件首先打开Android studio软件,然后点击右下角的Configure中的SDK Manager然后点击HTTP Proxy点击 Apply 后选择进入http://ping.chinaz.com/,进行 dl.google.com ping检查,选择大陆响应最短的IP节点。然后将IP地址加入hosts文件中。如果可以将(IP地址 dl....

2019-12-10 14:21:50 779

转载 The Bellman-Ford Algorithm 笔记

Single-Source Shortest Paths Revisited 1.1 The Single-Source Shortest Path Problem. Input: Directed graph G=(V,E)G=(V,E)G=(V,E), edge lengths cecec_e for each e∈Ee∈Ee \in E, source vertex s∈Vs∈Vs ...

2018-06-27 09:27:10 577

原创 Dynamic Programming--notes

Introduction, and WIS in Path Graphs 1. Problem Statement 1.1 Input: A path graph G=(V,E)G=(V,E)G=(V, E) with nonnegative weight on vertices. 1.2 Desired output: Subset of nonadajacent vertices -a...

2018-06-08 15:38:51 174

原创 Prim 算法的实现

最小生成树除了prim还有kruskal算法。Prim算法的实现,用到了优先队列。仅供参考的c++代码:#include &lt;iostream&gt;#include &lt;string&gt;#include &lt;stack&gt;#include &lt;fstream&gt;#include &lt;sstream&gt;#include &lt;ctime&gt;#i...

2018-06-03 17:29:47 1190

原创 并查集的实现

并查集的实现主要有两个功能:1.find(x),返回x的根结点,可以将其想象为一颗树。2.union(x,y),将x,y融合为一颗树.具体实现有1.parent[x]:指的是x的根结点.2.rank[x]:指以x为根结点时,从叶子到根结点的最大距离(hops)。为了使union方便,在进行union(x,y)操作时,选择将rank小的树的根结点改为rank较大树的根结点。仅仅改变rank小的根结点...

2018-06-03 17:16:26 152

原创 Algorithms-Advanced-Union-Find-notes

Lazy UnionsThe Union-Find Data Structure FIND: Given x∈Xx∈Xx\in X, return na,e of x’s group. UNION: Given x&amp;nbsp;&amp;amp;&amp;nbsp;yx&amp;nbsp;&amp;amp;&amp;nbsp;yx &amp; y, merge groups containing them. Previous solut

2018-06-03 12:26:43 155

原创 Algorithm-part3-week2

MST Review Input: Undirected graph G = (V, E),edges costs cecec_e. Output: Min-cost spanning tree(no cycles, connected). Assumptions : G is connected, distinct edge costs. Cut Property: If e is th...

2018-06-02 21:50:40 264

原创 Algorithm-part3-week1

Minimum spanning trees Informal goal: Connect a bunch of points together as cheaply as possible. Application: Clustering(more later), networking. Blazingly Fast Greedy Algorithms: −−−−-- Prim’s A...

2018-05-29 08:44:38 186

原创 Algorithms2-week4-hashtable

Hash Table: Supported Operations Purpose:maintain a (possibly evolving) set of stuff. (transactions, people+associated data, IP address, etc) Insert: add new record. Delete: delete existing reco...

2018-05-16 20:08:14 222

原创 Data structure notes

Data Structure Pooint: organize data so that it can be accessed quickly and usefully. Examples: lists,stacks,queues,heaps,search trees,hashtables, bloom filters, union-find, etc Rule of thumb: cho...

2018-05-12 19:41:07 144

原创 Algorithm(2)Graph search and connectivity-week1

1. Graph Primitives 1.1 Generic Graph Search Goal: 1) find everything findable from a given start vertex. 2) don’t explore anything twice.Goal : O(m+n) times. Generic Algorithm(given graph G, v...

2018-05-07 22:09:36 295

原创 图处理算法-Kosaraju's-算法

Kosaraju 算法实现1.用c++写了算法课的作业,计算了875714个顶点的有向图,计算了前5个最大连通分量的个数,用了两次DFS算法。 2.用c++开辟大数组容易出segment fault,后来改用堆开辟。图的邻接表用了链表表示。 VertexNode* adjList = new VertexNode[875714]; 3.Kosaraju算法流程不在此详述。深度优先...

2018-05-06 16:02:08 554

空空如也

空空如也

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

TA关注的人

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