自定义博客皮肤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)
  • 收藏
  • 关注

原创 [C++]C++ 函数指针 实现 函数名字符串 到 函数调用 cmath.h

代码功能从命令行读取格式为 函数名 数值 的输入,例如: log10 1000在命令行输出调用对应函数名的函数计算结果,例如: log10(1000) = 3完整源码// C++ code#include <iostream>#include <cmath>#include <map>typedef double (* PtrFun) (double x);class FunctionEn

2017-03-12 14:15:05 3251

原创 [Ruby笔记]31.ruby set 类型 交、并、补、异或 & + - ^ |

setset是Ruby的标准库的类;打开irb使用,需要先写语句 require 'set';codeirb$ irb --simple-prompt>> require 'set'=> true创建两个集合 ()里面放一个数组即可>> first = Set.new(["A","B","C","D"])=> #<Set: {"A", "B", "C", "D"}>>> sec

2017-01-26 00:03:59 2930

原创 [Ruby笔记]30.Ruby hash symbol 在哈希表中用符号作为键

reference 《The Well-Grounded Rubyist, Second Edition》 (https://www.manning.com/books/the-well-grounded-rubyist-second-edition)あついおっ~~~~~  ∧ ∧ γ⌒ヽ  (* 'ω')i ミ(二i ( ∪ ∪ ヽ、,_|| と_)_)  r-!!

2017-01-25 17:14:55 1489

原创 [Ruby笔记]29. Ruby yield from method to block 从方法到块

yieldyield关键字可以实现从方法method到块block的往返.exampleoutputPS E:\ruby> ruby test_yield.rb1.method2.block3.back to the methodsource codedef test puts "1.method" yield puts "3.back to the meth

2017-01-25 09:41:33 639 3

原创 [算法] 关于algs4 MSD.java 高位优先的字符串排序 的逐行代码解释

引用资料 [1] algs4 MSD.java 完整代码实现 http://algs4.cs.princeton.edu/51radix/MSD.java.html [2] 搭建java环境 以及安装algs4程序(win版本,其余可参考官网for students部分) http://algs4.cs.princeton.edu/windows/说明完整源码(见引用[

2017-01-12 02:28:11 1964 2

原创 [C++]C++ STL 环检测 带权有向图 找到全部的环

带权有向图找到全部的环完整源码#include <iostream>#include <vector> #include <tuple>#include <stack>#include <map>using namespace std;int V, E;int n;//带权有向图map<int, vector<tuple<int , int , double>>> EWD;bool m

2017-01-04 18:31:09 4934 6

原创 [C++] C++ DFS 记录层数两种写法dfs(int v) dfs(int v,int level)

DFS完整源码DFS.cpp// DFS.cpp#include <iostream>using namespace std;bool marked[10];int G[10][10];int V,E;int count;void dfs(int v) { count++; int level; level = count; for(int i = 0 ;i <

2017-01-03 21:46:57 3155

原创 [C++]C++ STL 拓扑排序序列 DFS 逆后序序列

拓扑排序序列完整源码#include <iostream>#include <vector> #include <stack>#include <queue>#include <map>using namespace std;int V, E;//有向图map<int, vector<int>> G;bool marked[100]; // v 是否已经被访问过?queue<i

2017-01-02 19:41:47 2690

原创 [C++]C++ STL 环检测 带权有向图 DFS

环检测完整源码#include <iostream>#include <vector> #include <tuple>#include <stack>#include <map>using namespace std;int V, E;//带权有向图map<int, vector<tuple<int , int , double>>> EWD;bool marked[100]; /

2017-01-02 18:36:20 2832

原创 [C++]C++ STL Dijkstra算法 存储多条相同最短路径 shortest path

Dijkstra存储多条相同最短路径使用list结构存储多个顶点(预备)完整源码#include <iostream>#include <list>using namespace std;int main(){ list<int> larray[100]; larray[0].push_back(0); larray[0].push_back(1); larray

2016-12-31 17:44:58 4514 3

原创 [C++]C++ STL Dijkstra算法 带权有向图(邻接表)单源最短路径求解

单源最短路径问题求解带权有向图(邻接表表示法)完整源码#include <iostream>#include <vector>#include <tuple>#include <map>using namespace std;map<int , vector<tuple<int, int, double>>> EWD;int main(){ int V, E; cin >>

2016-12-28 22:17:59 9962 1

原创 [C++]C++ STL priority_queue IndexPriorityQueue 索引优先队列 比较器

code#include <iostream>#include <vector>#include <queue>using namespace std;const int V = 10;double distTo[V]; // distTo[v] = shortest path of s->v struct LessThanByDist{ bool operator()(con

2016-09-07 01:32:39 2609

原创 [C++]C++重载 opeartor= must be a nonstatic member function?

codeusing namespace std;class C {public: int x; C () {} C(int a) : x(a) {} // member function C operator = (const C&);};C C::operator= (const C& param) { x = param.x; ret

2016-09-02 23:21:54 14935

原创 [C++]C++Pointers to classes 类指针 new 与object的对比

Code#include <iostream>using namespace std;class C { int one, two; public: C(int x, int y) : one(x), two(y) {} int sum(void) { return one + two; }};int main(){ int a = 1

2016-09-02 18:19:27 405

原创 [C++]C++ Pointers to functions 函数指针

C++ Pointers to functions#include <iostream>using namespace std;void hello(){ cout << "hello ";}void world(){ cout << "world! ";}void show(void(*fun)()) { (*fun)();}int main(){

2016-09-01 21:49:19 382

原创 [Ruby笔记]28.Ruby @@class_variables 类变量 vs @instance_variable 实例变量

@@class_variablesTestCase想象这样一个场景,一次小班授课,参加的学生有A B C 三人 ,这时候老师开始提问了,我们使用类Student 记录 : 到场的学生名单;每人答题次数;老师总的提问次数CodeClass Student 类@@names存着学生名单的数组 ; @@answers存着每个学生答题次数的哈希表 ;@@total_answers存着老师总

2016-07-19 23:42:52 623

原创 [Ruby笔记]27. ::String 前加双冒号确保使用built-in Ruby class

::String# File : ex.rbclass V class String attr_reader :picth def initialize(picth) @picth = picth + " From My String" puts @picth end end d

2016-07-07 18:48:06 1286

原创 [Ruby笔记]26. self 不变,每一次调用函数都会产生新的local scope

class C def hello(a, recurse = false) print "Now , self is : " p self print "self object id is : " p self.object_id print "And here's a : " puts a print "a has object id : " p a.object_id p

2016-07-07 18:11:01 713

原创 [算法]Java 实现 简单MyNode类型 无序链表 递归 添加 删除 遍历

MyNode 源码public class MyNode { private Node first; private int N; private class Node { String key; Node next; public Node(String key, Node next) { this.k

2016-07-04 14:05:19 811

原创 [Ruby笔记]25.local scope 本地作用域

code# file : nest2.rbclass A x = 'A' module M x = 'M' class B x = 'B' def show_x x = 'X' puts x end

2016-06-28 20:29:21 477

原创 [Ruby笔记]24.Ruby全局变量 $global_variable

PS C:\Users\Administrator> irb --simple-prompt>> class Time>> def hour_minute_seconds>> time = $hour + ":">> time << "#{$minute} : " if $minute>> time << "#{$second}">> end>> end=> :hour_minute_

2016-06-14 01:29:40 843

原创 [Ruby笔记]23.Ruby self “main class module instance”

# self !- **test_self.rb** ```puts "Top Level"puts "self is #{self}" # self is mainclass C puts "Class definition block : " puts "self is #{self}" #self is C # class method def self.x puts "Cl

2016-06-04 23:25:56 432

原创 [Ruby笔记]22.Ruby :: namespace 以及 instance method 与class method

:: namespace在module里面放了一个class,要实例化这个class,需要用M::C.new , module M 起到了namespace的作用,从视觉上大大加强代码的可读性:PS C:\Users\Administrator> irb --simple-prompt>> module M>> class C>> end>> end=> nil>> t = M::C.

2016-06-03 21:16:35 1749

原创 [Ruby笔记]21.Ruby public_method_defined? 以及 method_missing

public_method_defined?在A类中定义了一个hello方法,使用public_method_defined?就可以判断是不是存在 :PS C:\Users\Administrator\Rubycode> irb --simple-prompt>> class A>> def hello>> puts "hello hi">> end>> end>> A.pub

2016-06-03 20:23:38 720

原创 [Ruby笔记]20.Ruby super initialize class

# code in file `abc.rb````class SuperABC def initialize @a = 1 @b = 2 @c = 3 endendclass ABC < SuperABC def initialize super # keyword @a = 0 end def a puts @a end def b puts @b

2016-06-03 17:38:06 996

原创 [Ruby笔记]19.Ruby 2.0+ prepend 与 include

# code创建一个`win.rb` 文件:```PS C:\Users\Administrator\RubyCode> ls-a--- 2016/6/3 16:52 142 win.rb```使用`prepend M`语句 , `module win` :```module M def hello puts "Module win!" endend

2016-06-03 16:58:13 434

原创 [Ruby笔记]18.Ruby 继承 Inheritance 与 .superclass

- 打开`irb` ,定义一个`Super`类 ```PS C:\Users\Administrator> irb --simple-prompt>> class Super>> def say_hello>> "hello">> end>> end=> :say_hello>> class My < Super>> end```

2016-05-30 08:08:46 820

原创 [Ruby笔记]17.Ruby attribute attr_reader attr_writer attr_accessor attr

class Test attr_reader :name, :sex attr_writer :age attr_accessor :weight def initialize(name, sex, weight) @name = name @sex = sex @weight = weight endend

2016-05-29 09:05:24 795

原创 [Ruby笔记]16.Ruby 判断数字 .is_a?(Numeric) .to_i

PS C:\Users\Administrator\RubyCode> irb --simple-prompt>> 100.is_a?(Numeric)=> true

2016-05-29 08:39:58 4148

原创 [读书笔记]2.标准误差 标准差 信度 实例计算说明

- 标准差SD,有**样本**标准差和**总体**标准差,二者不同,可以通过公式换算,总的来说标准差SD是反映个体间的变异程度的指标,是反映个体距离平均数的离散程度的指标;- 标准误差SE是一种关于可靠性的估计指标;

2016-05-28 14:57:08 5473 1

原创 [Ruby笔记]15.@instance_variable 以及 糖“在方法名中可使用=”

class Sugar def price=(amount) @price = amount end def price @price endend

2016-05-27 12:21:32 803

原创 [Ruby笔记]14.Ruby local_variable

Ruby local_variable 可用命名格式a_anamefirst_namehello48user_ID_Ruby如何区分local_variable /keyword/ method call Identifier difference keyword 诸如def 、if之类keyword,Ruby内置一张关键词的表,可以直接判断出来 local_varia

2016-05-25 02:03:30 618

原创 [Ruby笔记]13.Ruby object .replace("") .dup .freeze

.replace()打开irb :PS C:\Users\Administrator> irb --simple-prompt创建字符串变量str ,值为“hello”,赋值给变量abc,本质是使abc指向同一个字符串对象,所以均输出为同一个“hello” :>> str = "Hello"=> "Hello">> abc = str=> "Hello"对str 变量使用.replac

2016-05-25 01:51:38 574

原创 [Ruby笔记]12.Ruby 方法参数变量优先级method(*arg)

def m(a,b=2,*c,d) puts "a = #{a} ,b = #{b} ,c = #{c} ,d = #{d} "endm(1,3)# a = 1 ,b = 2 ,c = [] ,d = 3m(1,3,5)# a = 1 ,b = 3 ,c = [] ,d = 5m(1,3,5,7)# a = 1 ,b = 3 ,c = [5] ,d = 7m(1,3,5,7,9)# a = 1 ,

2016-05-23 20:13:22 1114

原创 [Ruby笔记]11.Ruby == .equal? object .object_id .respond_to? .send()

obj = Object.newdef obj.hello "hello world"enddef obj.year "2016/05/23"endputs "obj's id is #{obj.object_id}"puts "Information : "request = gets.chompif obj.respond_to?(request)

2016-05-23 15:32:20 585

原创 [Ruby笔记]10. Ruby object return Boolean nil false #{}

>> if puts "Hello world">> puts "You can't see this">> endHello world=> nil

2016-05-23 14:20:02 562

原创 [Ruby笔记]9.Ruby文档工具 ri ruby-doc Windows CMD.exe Powershell

在Windows上安装ruby-doc ri 工具安装步骤Ruby的命令行文档工具ri ,一般安装步骤[1]1.在终端运行 gem install rdoc-data 安装2.然后需要生成 ri 数据,在终端运行 rdoc-data –install gem rdoc –all –overwrite gem rdoc --all --ri --no-rdoc可能会遭

2016-05-21 02:09:45 938

原创 [Ruby笔记]8. Ruby Rakefile rake 删除文件 确认

PS C:\Users\Administrator\RubyCode> rake admin:clean_tmpDelete ./tmp/新建文本文档 - 副本 (2).txt? yDelete ./tmp/新建文本文档 - 副本 (3).txt? yDelete ./tmp/新建文本文档 - 副本 (4).txt? yDelete ./tmp/新建文本文档 - 副本 (5).txt? yDelete ./

2016-05-21 01:04:59 585

原创 [Ruby笔记]7.ruby -e ' " 单引号、双引号对比

使用`ruby -e "..."`可以在命令行直接运行脚本```PS C:\Users\Administrator\RubyCode> ruby -e "print 'Enter a name: '; print gets.reverse"Enter a name: TommoTPS```

2016-05-20 03:16:03 1771

原创 [Ruby笔记]6. Ruby load require 使用对比

# load "loadee.rb"# require "./loadee.rb"# require "./loadee"require_relative "loadee"

2016-05-19 02:07:40 521

空空如也

空空如也

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

TA关注的人

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