class Array def quick_sort return self if self.length<=1 k = self[0] head = 0 tail = self.length - 1 while head < tail (tail-head).times do if self[tail] < k self[tail], self[head] = self[head], self[tail] break end tail = tail - 1 end (tail-head…
var sort = (function () { //快速排序 var quickSort = { partition: function (array, low, high) { if (low >= high) { return; } var key = array[high]; var middle = low; for (var i = low; i < high; i++) { if (array[i] < key) { if (i != middle) { var tmp…
需求: 商场收银软件,根据客户购买物品的单价和数量,计算费用,会有促销活动,打八折,满三百减一百之类的. 一,使用工厂模式. # -*- encoding: utf-8 -*- #现金收费抽象类 class CashSuper def accept_cash(money) end end #正常收费子类 class CashNormal < CashSuper def accept_cash(money) money end end #打折收费子类 class CashRebate < Cas…
需求: 股民买卖股票 初步代码: # -*- encoding: utf-8 -*- #股票1 class Stock1 def buy puts '股票1买入' end def sell puts '股票1卖出' end end #股票2 class Stock2 def buy puts '股票2买入' end def sell puts '股票2卖出' end end #股票3 class Stock3 def buy puts '股票3买入' end def sell puts '股票3…
"use strict" var arr1=[11,21,3,4,0]; function qSort(arr){ var mid,left,right,len,i,j,emptyArr,emptyArr2; len = arr.length; left = []; right = []; emptyArr=[]; emptyArr2=[]; j = 0; if (len < 2){ return arr }else{ mid = arr[0]; for (i=1; i<l…