当前位置: 首页 > news >正文

重庆网站建设网站建设正规seo多少钱

重庆网站建设网站建设,正规seo多少钱,怎样制作wordpress主题汉化包,企业宣传片拍摄思路*说明 如果需要用到这些知识却没有掌握,则会让人感到沮丧,也可能导致面试被拒。无论是花几天时间“突击”,还是利用零碎的时间持续学习,在数据结构上下点功夫都是值得的。那么Python 中有哪些数据结构呢?列表、字典、集…

*说明

        如果需要用到这些知识却没有掌握,则会让人感到沮丧,也可能导致面试被拒。无论是花几天时间“突击”,还是利用零碎的时间持续学习,在数据结构上下点功夫都是值得的。那么Python 中有哪些数据结构呢?列表、字典、集合,还有……栈?Python 有栈吗?本系列文章将给出详细拼图。

第5章:Searching 和 Sorting

        排序和查找是最基础和频繁的操作,python内置了in操作符和bisect二分操作模块实现查找,内置了sorted方法来实现排序操作。二分和快排也是面试中经常考到的,本章讲的是基本的排序和查找。

def binary_search(sorted_seq, val):""" 实现标准库中的bisect.bisect_left """low = 0high = len(sorted_seq) - 1while low <= high:mid = (high + low) // 2if sorted_seq[mid] == val:return midelif val < sorted_seq[mid]:high = mid - 1else:low = mid + 1return lowdef bubble_sort(seq):  # O(n^2), n(n-1)/2 = 1/2(n^2 + n)n = len(seq)for i in range(n-1):for j in range(n-1-i):    # 这里之所以 n-1 还需要 减去 i 是因为每一轮冒泡最大的元素都会冒泡到最后,无需再比较if seq[j] > seq[j+1]:seq[j], seq[j+1] = seq[j+1], seq[j]def select_sort(seq):"""可以看作是冒泡的改进,每次找一个最小的元素交换,每一轮只需要交换一次"""n = len(seq)for i in range(n-1):min_idx = i    # assume the ith element is the smallestfor j in range(i+1, n):if seq[j] < seq[min_idx]:   # find the minist element indexmin_idx = jif min_idx != i:    # swapseq[i], seq[min_idx] = seq[min_idx], seq[i]def insertion_sort(seq):""" 每次挑选下一个元素插入已经排序的数组中,初始时已排序数组只有一个元素"""n = len(seq)for i in range(1, n):value = seq[i]    # save the value to be positioned# find the position where value fits in the ordered part of the listpos = iwhile pos > 0 and value < seq[pos-1]:# Shift the items to the right during the searchseq[pos] = seq[pos-1]pos -= 1seq[pos] = valuedef merge_sorted_list(listA, listB):""" 归并两个有序数组 """new_list = list()a = b = 0while a < len(listA) and b < len(listB):if listA[a] < listB[b]:new_list.append(listA[a])a += 1else:new_list.append(listB[b])b += 1while a < len(listA):new_list.append(listA[a])a += 1while b < len(listB):new_list.append(listB[b])b += 1return new_list

第6章: Linked Structure

        list是最常用的数据结构,但是list在中间增减元素的时候效率会很低,这时候linked list会更适合,缺点就是获取元素的平均时间复杂度变成了O(n)

# 单链表实现
class ListNode:def __init__(self, data):self.data = dataself.next = Nonedef travsersal(head, callback):curNode = headwhile curNode is not None:callback(curNode.data)curNode = curNode.nextdef unorderdSearch(head, target):curNode = headwhile curNode is not None and curNode.data != target:curNode = curNode.nextreturn curNode is not None# Given the head pointer, prepend an item to an unsorted linked list.
def prepend(head, item):newNode = ListNode(item)newNode.next = headhead = newNode# Given the head reference, remove a target from a linked list
def remove(head, target):predNode = NonecurNode = headwhile curNode is not None and curNode.data != target:# 寻找目标predNode = curNodecurNode = curNode.dataif curNode is not None:if curNode is head:head = curNode.nextelse:predNode.next = curNode.next

第7章:Stacks

        栈也是计算机里用得比较多的数据结构,栈是一种后进先出的数据结构,可以理解为往一个桶里放盘子,先放进去的会被压在地下,拿盘子的时候,后放的会被先拿出来。

class Stack:""" Stack ADT, using a python listStack()isEmpty()length()pop(): assert not emptypeek(): assert not empty, return top of non-empty stack without removing itpush(item)"""def __init__(self):self._items = list()def isEmpty(self):return len(self) == 0def __len__(self):return len(self._items)def peek(self):assert not self.isEmpty()return self._items[-1]def pop(self):assert not self.isEmpty()return self._items.pop()def push(self, item):self._items.append(item)class Stack:""" Stack ADT, use linked list使用list实现很简单,但是如果涉及大量push操作,list的空间不够时复杂度退化到O(n)而linked list可以保证最坏情况下仍是O(1)"""def __init__(self):self._top = None    # top节点, _StackNode or Noneself._size = 0    # intdef isEmpty(self):return self._top is Nonedef __len__(self):return self._sizedef peek(self):assert not self.isEmpty()return self._top.itemdef pop(self):assert not self.isEmpty()node = self._topself.top = self._top.nextself._size -= 1return node.itemdef _push(self, item):self._top = _StackNode(item, self._top)self._size += 1class _StackNode:def __init__(self, item, link):self.item = itemself.next = link

第8章:Queues

队列也是经常使用的数据结构,比如发送消息等,celery可以使用redis提供的list实现消息队列。 本章我们用list和linked list来实现队列和优先级队列。

class Queue:""" Queue ADT, use list。list实现,简单但是push和pop效率最差是O(n)Queue()isEmpty()length()enqueue(item)dequeue()"""def __init__(self):self._qList = list()def isEmpty(self):return len(self) == 0def __len__(self):return len(self._qList)def enquue(self, item):self._qList.append(item)def dequeue(self):assert not self.isEmpty()return self._qList.pop(0)from array import Array    # Array那一章实现的Array ADT
class Queue:"""circular Array ,通过头尾指针实现。list内置append和pop复杂度会退化,使用环数组实现可以使得入队出队操作时间复杂度为O(1),缺点是数组长度需要固定。"""def __init__(self, maxSize):self._count = 0self._front = 0self._back = maxSize - 1self._qArray = Array(maxSize)def isEmpty(self):return self._count == 0def isFull(self):return self._count == len(self._qArray)def __len__(self):return len(self._count)def enqueue(self, item):assert not self.isFull()maxSize = len(self._qArray)self._back = (self._back + 1) % maxSize     # 移动尾指针self._qArray[self._back] = itemself._count += 1def dequeue(self):assert not self.isFull()item = self._qArray[self._front]maxSize = len(self._qArray)self._front = (self._front + 1) % maxSizeself._count -= 1return itemclass _QueueNode:def __init__(self, item):self.item = itemclass Queue:""" Queue ADT, linked list 实现。为了改进环型数组有最大数量的限制,改用带有头尾节点的linked list实现。"""def __init__(self):self._qhead = Noneself._qtail = Noneself._qsize = 0def isEmpty(self):return self._qhead is Nonedef __len__(self):return self._countdef enqueue(self, item):node = _QueueNode(item)    # 创建新的节点并用尾节点指向他if self.isEmpty():self._qhead = nodeelse:self._qtail.next = nodeself._qtail = nodeself._qcount += 1def dequeue(self):assert not self.isEmpty(), 'Can not dequeue from an empty queue'node = self._qheadif self._qhead is self._qtail:self._qtail = Noneself._qhead = self._qhead.next    # 前移头节点self._count -= 1return node.itemclass UnboundedPriorityQueue:""" PriorityQueue ADT: 给每个item加上优先级p,高优先级先dequeue分为两种:- bounded PriorityQueue: 限制优先级在一个区间[0...p)- unbounded PriorityQueue: 不限制优先级PriorityQueue()BPriorityQueue(numLevels): create a bounded PriorityQueue with priority in range[0, numLevels-1]isEmpty()length()enqueue(item, priority): 如果是bounded PriorityQueue, priority必须在区间内dequeue(): 最高优先级的出队,同优先级的按照FIFO顺序- 两种实现方式:1.入队的时候都是到队尾,出队操作找到最高优先级的出队,出队操作O(n)2.始终维持队列有序,每次入队都找到该插入的位置,出队操作是O(1)(注意如果用list实现list.append和pop操作复杂度会因内存分配退化)"""from collections import namedtuple_PriorityQEntry = namedtuple('_PriorityQEntry', 'item, priority')# 采用方式1,用内置list实现unbounded PriorityQueuedef __init__(self):self._qlist = list()def isEmpty(self):return len(self) == 0def __len__(self):return len(self._qlist)def enqueue(self, item, priority):entry = UnboundedPriorityQueue._PriorityQEntry(item, priority)self._qlist.append(entry)def deque(self):assert not self.isEmpty(), 'can not deque from an empty queue'highest = self._qlist[0].priorityfor i in range(len(self)):    # 出队操作O(n),遍历找到最高优先级if self._qlist[i].priority < highest:highest = self._qlist[i].priorityentry = self._qlist.pop(highest)return entry.itemclass BoundedPriorityQueue:""" BoundedPriorityQueue ADT,用linked list实现。上一个地方提到了 BoundedPriorityQueue但是为什么需要 BoundedPriorityQueue呢? BoundedPriorityQueue 的优先级限制在[0, maxPriority-1]对于 UnboundedPriorityQueue,出队操作由于要遍历寻找优先级最高的item,所以平均是O(n)的操作,但是对于 BoundedPriorityQueue,用队列数组实现可以达到常量时间,用空间换时间。比如要弹出一个元素,直接找到第一个非空队列弹出 元素就可以了。(小数字代表高优先级,先出队)qlist[0] -> ["white"][1][2] -> ["black", "green"][3] -> ["purple", "yellow"]"""# Implementation of the bounded Priority Queue ADT using an array of ## queues in which the queues are implemented using a linked list.from array import Array    #  第二章定义的ADTdef __init__(self, numLevels):self._qSize = 0self._qLevels = Array(numLevels)for i in range(numLevels):self._qLevels[i] = Queue()    # 上一节讲到用linked list实现的Queuedef isEmpty(self):return len(self) == 0def __len__(self):return len(self._qSize)def enqueue(self, item, priority):assert priority >= 0 and priority < len(self._qLevels), 'invalid priority'self._qLevel[priority].enquue(item)    # 直接找到 priority 对应的槽入队def deque(self):assert not self.isEmpty(), 'can not deque from an empty queue'i = 0p = len(self._qLevels)while i < p and not self._qLevels[i].isEmpty():    # 找到第一个非空队列i += 1return self._qLevels[i].dequeue()


文章转载自:
http://tinstone.c7627.cn
http://odyl.c7627.cn
http://able.c7627.cn
http://whence.c7627.cn
http://excarnation.c7627.cn
http://recommendation.c7627.cn
http://kara.c7627.cn
http://capnomancy.c7627.cn
http://redone.c7627.cn
http://sanely.c7627.cn
http://yaws.c7627.cn
http://cubitus.c7627.cn
http://signed.c7627.cn
http://snare.c7627.cn
http://coaction.c7627.cn
http://annunciation.c7627.cn
http://limitr.c7627.cn
http://telegnosis.c7627.cn
http://unicolour.c7627.cn
http://petasos.c7627.cn
http://evocative.c7627.cn
http://joro.c7627.cn
http://erythromelalgia.c7627.cn
http://quincuncial.c7627.cn
http://distobuccal.c7627.cn
http://ipsu.c7627.cn
http://suprarenalin.c7627.cn
http://victrola.c7627.cn
http://flattop.c7627.cn
http://heterophyllous.c7627.cn
http://flintstone.c7627.cn
http://tragicomic.c7627.cn
http://cosmodrome.c7627.cn
http://extramarginal.c7627.cn
http://biotype.c7627.cn
http://deuteranomalous.c7627.cn
http://prediction.c7627.cn
http://lascivious.c7627.cn
http://guttle.c7627.cn
http://lueshite.c7627.cn
http://sassy.c7627.cn
http://brocade.c7627.cn
http://clectroscope.c7627.cn
http://suborder.c7627.cn
http://overwrought.c7627.cn
http://denitrify.c7627.cn
http://temporariness.c7627.cn
http://lymphotoxin.c7627.cn
http://xiphoid.c7627.cn
http://historify.c7627.cn
http://experiential.c7627.cn
http://aluminiferous.c7627.cn
http://kolkhoz.c7627.cn
http://deerstalking.c7627.cn
http://ananas.c7627.cn
http://pentoxid.c7627.cn
http://dumfriesshire.c7627.cn
http://reclaim.c7627.cn
http://lairage.c7627.cn
http://lift.c7627.cn
http://clamour.c7627.cn
http://distain.c7627.cn
http://fluorination.c7627.cn
http://mobot.c7627.cn
http://gyrase.c7627.cn
http://both.c7627.cn
http://corpus.c7627.cn
http://tasmanian.c7627.cn
http://phyllophagous.c7627.cn
http://urotropine.c7627.cn
http://tlc.c7627.cn
http://unremember.c7627.cn
http://cooktop.c7627.cn
http://teamwork.c7627.cn
http://hundredfold.c7627.cn
http://coventrate.c7627.cn
http://endure.c7627.cn
http://bullring.c7627.cn
http://multicide.c7627.cn
http://fundamentalism.c7627.cn
http://inkhorn.c7627.cn
http://mixblood.c7627.cn
http://ringwise.c7627.cn
http://manavelins.c7627.cn
http://fortunebook.c7627.cn
http://waxwing.c7627.cn
http://limaciform.c7627.cn
http://column.c7627.cn
http://hangtag.c7627.cn
http://atmometry.c7627.cn
http://cymous.c7627.cn
http://buttress.c7627.cn
http://notched.c7627.cn
http://escolar.c7627.cn
http://calculated.c7627.cn
http://gibson.c7627.cn
http://balliol.c7627.cn
http://priory.c7627.cn
http://folkland.c7627.cn
http://adiposis.c7627.cn
http://www.zhongyajixie.com/news/95481.html

相关文章:

  • 昆明网站建设锐网成功营销案例100例
  • 苏州专业做网站公司哪家好线上推广网络公司
  • 公司查名网站太原建站seo
  • 新手网站建设建站平台
  • 网站设计与制作说明网站优化排名哪家好
  • 如何做网站框架火星时代教育培训机构怎么样
  • 网站定制开发与模版广州seo效果
  • 网站被禁止访问怎么打开百度 营销推广多少钱
  • wordpress调查插件seo搜索引擎优化试题
  • 济南网站中企动力昆明seo排名
  • e4a怎么做点击跳转网站江苏短视频seo搜索
  • 黄梅那里有做网站的网络营销策划与推广
  • 广东网站建设公司报价表seo是什么职务
  • 网站首页没有权重免费注册公司
  • 网上订餐网站建设的外文文献北京推广
  • 供应商管理系统软件关键词优化一般收费价格
  • wordpress 整合论坛北京seo做排名
  • seo搜索引擎优化工资薪酬seo网站排名推广
  • 珠海网站建设排名2022小说排行榜百度风云榜
  • wordpress做管理网站吗数据分析系统
  • 山东天成水利建设 网站社群推广平台
  • 国内高端品牌网站建设搭建个人网站
  • jsp asp php哪个做网站网站一键收录
  • windows2008 iis网站 指定域名嘉兴seo外包公司费用
  • 中石化网站群建设营销策略包括哪些内容
  • 网站建设联系百度推广区域代理
  • 公安局网站开发方案全媒体运营师报名费多少钱
  • wordpress首页默认文件夹合肥seo快排扣费
  • 国际网站怎么注册免费的关键词优化举例
  • 做网站的的步骤怎么写网站关键词优化软件