• python-数据结构代码 链表(无序链表、有序链表)


    class Node:
        def __init__(self,initdata):
            self.data = initdata
            self.next = None
    
        def getData(self):
            return self.data
    
        def getNext(self):
            return self.next
    
        def setData(self,newdata):
            self.data = newdata
    
        def setNext(self,newnext):
            self.next = newnext
    
    class UnorderedList:
        def __init__(self):
            self.head = None
    
        def isEmpty(self):
            return self.head == None
    
        def add(self,item):
            temp = Node(item)
            temp.setNext(self.head)
            self.head = temp
        
        def size(self):
            current = self.head
            count=0
            while current != None:
                count=count+1
                current=current.getNext()
            return count
        
        def search(self,item):
            current=self.head
            found=False
            while current!-None and not foune:
                if current.getData() == item:
                    found=True
                else:
                    current=current.getNext()
            return found
    
        def remove(self,item):
            current=self.head
            previous=None
            found=False
            while not found:
                if current.getData()==item:
                    found=True
                else:
                    previous=current
                    current=current.getNext()
            if previous==None:
                self.head=current.getNext()
            else:
                previous.setNext(current.getNext())
    
    class OrderedList:
        def __init__(self):
            self.head = None
    
        def isEmpty(self):
            return self.head == None
        
        def size(self):
            current = self.head
            count=0
            while current != None:
                count=count+1
                current=current.getNext()
            return count
    
        def remove(self,item):
            current=self.head
            previous=None
            found=False
            while not found:
                if current.getData()==item:
                    found=True
                else:
                    previous=current
                    current=current.getNext()
            if previous==None:
                self.head=current.getNext()
            else:
                previous.setNext(current.getNext())
    
        def search(self,item):
            current=self.head
            found=False
            stop=False
            while current!=None and not found and not stop:
                if current.getData()==item:
                    found=True
                else:
                    if current.getData()>item:
                        stop=True
                    else:
                        current=current.getNext()
            return found
    
        def add(self,item):
            current=self.head
            previous=None
            stop=False
            while current!=None and not stop:
                if current.getData()>item:
                    stop=True
                else:
                    previous=current
                    current=current.getNext()
            temp=Node(item)
            if previous==None:
                temp.setNext(self.head)
                self.head=temp
            else:
                temp.setNext(current)
                previous.setNext(temp)
  • 相关阅读:
    爬虫header和cookie
    爬虫代理squid
    response对象
    pyspider中内容选择器常用方法汇总
    非阻塞 sleep
    post请求体过大导致ngx.req.get_post_args()取不到参数体的问题
    常用lua代码块
    nginx静态文件缓存的解决方案
    lua-resty-gearman模块
    非在线PDF转图片!!!
  • 原文地址:https://www.cnblogs.com/lely/p/10137614.html
Copyright © 2020-2023  润新知