def merge_link(left, mid, right): ''' @brief 合并linklist @param left 第一个链表的头 @param mid 第一个链表的结尾,第二个链表的头 @param right 第二个链表的结尾 ''' ret = linklist.linklist() rst_index = left snd_index = mid ret_index = ret while rst_index != mid and snd_index != right: if rst_index.data < snd_index.data: tmp = rst_index rst_index = rst_index.next ret_index.next = tmp else: tmp = snd_index snd_index = snd_index.next ret_index.next = tmp ret_index = ret_index.next if rst_index != mid: ret_index.next = rst_index if snd_index != right: ret_index.next = snd_index return ret
def insert(self, item): index = self.head while None is not index and index.next.data > item: index = index.next node = linklist.linklist(item, index.next) index.next = node self.len += 1
def push(self, data): ''' @brief 压入,从head操作 @param data 压入的数据 ''' node = linklist.linklist(self.head, data) self.head = node self.len += 1
def build(self, array): for i in range(len(array)): head = self.rows[i] for j in range(len(array[0])): if array[i][j] != 0: node = linklist.linklist(matrix_ele(j, array[i][j]), head.next) head.next = node
def put(self, key, value): i = self.find(key) if i.next is None: item = linklist.linklist([key, value], None) i.next = item self.len += 1 else: i.next.data[1] = value
def move_front(line): ''' @brief 1.3.40 前移编码,创建一个链表,遍历line,每次遇到表中存在的元素将新元素插入到表头,删除表中存在的节点 ''' head = linklist.linklist() for ch in line: node = linklist.linklist.find(head, ch) if node == None: node = linklist.linklist(head, ch) head = node elif head == node and head.data == ch: continue else: tmp = node.next node.next = node.next.next tmp.next = head head = tmp return head
def link_remove(link, value): ''' @brief 1.3.26 删除链表link中所有值为value的item @param link 需要进行操作的链表 @param value 目标值 ''' head = linklist.linklist(next=link, data=0) index = head while index.next is not None: if index.next.data == value: tmp = index.next index.next = index.next.next del tmp link = head.next del head return link
def extend_link(link, size): ''' @brief 扩展link节点,如果link为空则默认创建一个的链表 @param link链表需要插入的节点 ''' is_none = False if link is None: is_none = True index = link while size != 0: node = linklist.linklist(data=0, next=None) if index.next is not None: node.next = index.next.next index.next = node index = index.next size -= 1 if is_none: index.next = link return link
def __init__(self, size): ''' @param size 散列表大小 ''' super().__init__() self.list = [linklist.linklist()] * size
def insert(self, item): node = linklist.linklist(item, self.head.next) self.head.next = node self.len += 1
def __init__(self): self.head = linklist.linklist(0) #头节点
def __init__(self, array): super().__init__() self.rows = [linklist.linklist(None, None)] * len(array) self.col = len(array[0]) self.row = len(self.rows)
def __init__(self): super(link_st, self).__init__() self.head = linklist.linklist(None, None) self.len = 0