码迷,mamicode.com
首页 >  
搜索关键字:def    ( 28626个结果
用Python实现几种排序算法
#coding=utf-8# 1 快速排序算法def qksort(list): if len(list)=pivot] return qksort(less)+[pivot]+qksort(greater) q=[1,3,8,3,2,6,5,3,5,7]t=qksort(...
分类:编程语言   时间:2015-01-02 01:06:51    阅读次数:189
scala简要: 继承
scala扩展类的方式同样是使用extends关键字,重写一个非抽象方法必须使用override修饰符,用isInstanceOf方法判断某个对象是否属于某个特定的类,只有主构造器可以调用超类的构造器。字段重写时的限制:-def 只能重写另一个def-val只能重写另一个val或不带参数的def-var只能重写另一个抽象的var构造顺序问题的根本原因——java允许在超类的构造方法中调用子类的方法...
分类:其他好文   时间:2015-01-01 21:17:43    阅读次数:174
Scala:HelloWorld
代码1 object HelloWorld {2 def main(args: Array[String]): Unit = {3 println("Hello world") 4 }5 }解说object关键字相当于static(更确切的说法是单例模式的一种语言层面...
分类:其他好文   时间:2015-01-01 21:07:39    阅读次数:197
POJ 3468(树状数组的威力)
之前说过这是线段树的裸题,但是当看了http://kenby.iteye.com/blog/962159这篇题解后我简直震惊了,竟然能如此巧妙地转化为用树状数组来处理,附上部分截图(最好还是进入原网址细细品味):依照他的思路附上我的代码: 1 #include 2 #include 3 #def.....
分类:编程语言   时间:2015-01-01 17:15:28    阅读次数:198
POJ 3067 Japan (树状数组)
题目地址:POJ 3067 按x为第一关键字从小到大排序,再按y为第二关键字从小到大排序,然后用y来建立树状数组,每次找比y大的就是每次更新的交点数。 代码如下: #include #include #include #include #include #include #include #include #include using namespace std; #def...
分类:编程语言   时间:2015-01-01 11:18:05    阅读次数:257
《大话设计模式》ruby版代码:装饰模式
需求:给人搭配不同的服饰代码版本一# -*- encoding: utf-8 -*-class Person attr_accessor :name def initialize(name) @name = name end def wear_t...
分类:其他好文   时间:2014-12-31 22:49:12    阅读次数:249
Scala中的Implicit(隐式转换,隐式参数,隐式类)
文章来自:http://www.cnblogs.com/hark0623/p/4196452.html 转发请注明代码如下:/** * 隐式转换 隐式参数 隐式类 *///隐式转换class Implicit(a: A) { def Test: Unit = { println("Im...
分类:其他好文   时间:2014-12-31 21:21:55    阅读次数:208
python super
class?A(object):????#?A?must?be?new-style?class ??def?__init__(self):???print?"enter?A" ???print?"leave?A"class?B(C):?????#?A?-->?C ??def?__init__(self):???pri...
分类:编程语言   时间:2014-12-31 16:35:23    阅读次数:192
python学习笔记十二:类的定义
demo#!/usr/bin/pythonclass Person: name = 'jim' age = 25 def say(self): print 'My name is ' + self.name + ', and age is ' + str(self.a...
分类:编程语言   时间:2014-12-31 14:17:44    阅读次数:188
Python脚本,自动更新host,添加or更新本机hosts
#!/usr/bin/env python# -*- coding: utf-8 -*- import urllib2,re,platform#urlib2抓取网页def getContent(url, timeout=5): content = None try: res...
分类:编程语言   时间:2014-12-31 12:54:18    阅读次数:234
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!