首页 文章 精选 留言 我的

精选列表

搜索[Java实现],共10000篇文章
优秀的个人博客,低调大师

排序算法的python实现

本文所有的排序方法都在列表上进行操作,首先定义交换任意两项位置的函数swap。 def swap (x,i,j): """ 交换x的i,j位置元素 """ temp = x[i] x[i] = x[j] x[j] = temp 1、选择排序 排序算法的逻辑非常简单,首先搜索整个列表,找到最小项的位置,如果该位置不是列表的第1项,就交换这两个位置的元素。然后从列表的第2个元素开始,重复上述过程,直到算法达到整个过程的最后一个位置,图形解释如下 代码如下 def selectionSort (x): i = 0 while i < len(x) - 1 : minindex = i j = i + 1 while j < len(x) : if x[minindex] > x[j]: minindex = j j+= 1 if minindex

优秀的个人博客,低调大师

JavaScript是怎样AOP实现?

AOP的概念,使用过Spring的人应该都不陌生了。Dojo中,也是支持AOP的。对于JavaScript的其他框架、库不知道有没有AOP的支持。而Aop又叫面向切面编程,用过spring的同学肯定对它非常熟悉,而在js中,AOP是一个被严重忽视的技术点,这次就来说说AOP在js中的妙用 AOP的思维就是在目标方法前后加入代码: var result=null; try{ before(); result = targetMethod(params); }(catch e){ error(); }finlly{ after(); } return result; 在JavaScript中要达到AOP的效果可以利用apply(ctx,arguments)来达到目的,请看下面demo: 这是一个原始的代码: function Person(options){ options = options ? options : {}; this.id = options.id; this.age = options.age>0 ? options.age:0; } Person.prototype.show=function(){ console.log("id: "+this.id + " age: "+ this.age); }; var p = new Person({ id:'test1', age:1 }); p.show(); 现在想要对show方法植入代码,利用apply这样写就Ojbk了: var targetFunc = Person.prototype.show; var proxyFunc = function(){ var ctx = this; console.log("before ..."); targetFunc.apply(ctx, arguments); console.log("after ..."); } Person.prototype.show = proxyFunc; p = new Person({ id:"test2", age:2//欢迎加入全栈开发交流圈一起学习交流:864305860 });//面向1-3年前端人员 p.show();//帮助突破技术瓶颈,提升思维能力 如果要对各种方法植入,这样写肯定是不方便了,所以呢,将这个代码织入的过程提成一个通用的工具: function Interceptor(){ } Interceptor.prototype.before = function(callContext, params){ console.log("before... ", callContext, params); } Interceptor.prototype.after = function(callContext, params){ console.log("after... ", callContext, params); } Interceptor.prototype.error = function(callContext, params){ console.log("error... ", callContext, params); } var InjectUtil = (function(){ function inject(obj, methodName, interceptor){ var targetFun = obj\[methodName\]; if(typeof targetFun == "function"){ var proxyFun = genProxyFun(targetFun, interceptor); obj\[methodName\] = proxyFun; } } function genProxyFun(targetFun, interceptor){ var proxyFunc = function(){ var ctx = this; var result = null; interceptor.before(ctx, arguments); try{//欢迎加入全栈开发交流圈一起学习交流:864305860 result= targetFunc.apply(ctx, arguments); }catch(e){ interceptor.error(ctx, arguments); }finally{ interceptor.after(ctx, arguments); } return result; }; return proxyFunc; }; return { inject:inject } })(); 测试: Person.prototype.show=function(){ console.log("id: "+this.id + " age: "+ this.age); }; InjectUtil.inject(Person.prototype,"show",new Interceptor()); var p = new Person({ id:"test3", age:3 }); p.show(); 结语 > 感谢您的观看,如有不足之处,欢迎批评指正。

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码