Пример #1
0
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
Пример #2
0
    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
Пример #3
0
 def push(self, data):
     '''
     @brief  压入,从head操作
     @param  data    压入的数据
     '''
     node = linklist.linklist(self.head, data)
     self.head = node
     self.len += 1
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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
Пример #9
0
 def __init__(self, size):
     '''
     @param  size    散列表大小
     '''
     super().__init__()
     self.list = [linklist.linklist()] * size
Пример #10
0
 def insert(self, item):
     node = linklist.linklist(item, self.head.next)
     self.head.next = node
     self.len += 1
Пример #11
0
 def __init__(self):
     self.head = linklist.linklist(0)  #头节点
Пример #12
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)
Пример #13
0
 def __init__(self):
     super(link_st, self).__init__()
     self.head = linklist.linklist(None, None)
     self.len = 0