Example #1
0
def main():
    n1 = Node('say')
    n2 = Node('hello')
    n1.next = n2

    linked_list = Tail_Node_List(n1)
    linked_list.insert_tail('world')
    linked_list.print_list()
Example #2
0
def main():
    n1 = Node('say')
    n2 = Node('world')
    n1.next = n2

    linked_list = Between_insert_linked_list(n1)
    linked_list.insert_between(n1, 'hello')
    linked_list.print_list()
Example #3
0
    def insert_between(self, prev_node, data):
        if (prev_node == None):
            print('no previous node!')
            return

        new_node = Node(data)
        # 以下順序不能搞錯
        new_node.next = prev_node.next  # 新插入的node的next為原本prev_node的next
        prev_node.next = new_node  # prev的next就是新的node
 def __init__(self, name, children=[],width=-1,height=-1, parms=[]):
     Node.__init__(self, name, width, height)
     self.children = children
     self.relief = TK.GROOVE # Default
     if parms:
         self.width_type = parms[0]
         self.child_h_padding = parms[4]
         self.height_type = parms[1]
         self.child_v_padding = parms[5]
         self.x_align = parms[2]
         self.y_align = parms[3]
Example #5
0
 def __init__(self, name, children=[], width=-1, height=-1, parms=[]):
     Node.__init__(self, name, width, height)
     self.children = children
     self.relief = TK.GROOVE  # Default
     if parms:
         self.width_type = parms[0]
         self.child_h_padding = parms[4]
         self.height_type = parms[1]
         self.child_v_padding = parms[5]
         self.x_align = parms[2]
         self.y_align = parms[3]
 def __init__(self, name, columns=None, data=None, view_rows=None,
              cellheight=TABLE_CELLHEIGHT, h_gap=TABLE_H_GAP,
              v_gap=TABLE_V_GAP, color=TABLE_COLOR):
     Node.__init__(self, name)
     self.color = color
     self.columns = columns
     self.data = data
     self.view_rows = view_rows
     self.v_gap = v_gap
     self.h_gap = h_gap
     self.cellheight = cellheight
     self.v_scroll = False
     if columns and data:
         if not view_rows:
             self.view_rows = len(data)
         self.v_scroll = (self.view_rows < len(data))
         self.table_dimensions()
Example #7
0
    def insert_tail(self, data):
        new_node = Node(data)
        if (self.head == None):
            self.head = new_node
            return

        point = self.head
        while (point.next):
            point = point.next
        point.next = new_node  # 找到最後一個node
Example #8
0
 def insert_heading(self, newData):
     newNode = Node(newData)
     newNode.next = self.head
     # 把原本資料的頭接到新開頭的next,
     # e.g. 1 -> 2 -> 3 >> 新增一個0 >> 0 -> 1...
     self.head = newNode
Example #9
0
from basic_node import Node
from basic_node import printNodes


class Node_List():
    def __init__(self, headNode=None):
        self.head = headNode

    def print_list(self):
        printNodes(self.head)

    def insert_heading(self, newData):
        newNode = Node(newData)
        newNode.next = self.head
        # 把原本資料的頭接到新開頭的next,
        # e.g. 1 -> 2 -> 3 >> 新增一個0 >> 0 -> 1...
        self.head = newNode


if (__name__ == '__main__'):
    n1 = Node(10)
    n2 = Node(20)
    n1.next = n2

    linked_list = Node_List(n1)
    linked_list.insert_heading(30)
    linked_list.print_list()
from basic_node import Node
from basic_node import printNodes

n1 = Node('a')
n2 = Node('b')
n3 = Node('c')

n1.next = n2
n2.next = n3

if (__name__ == '__main__'):  # 只有此檔案才會被呼叫
    printNodes(n1)
Example #11
0
 def __init__(self, name='', width = -1, height = -1):
     Node.__init__(self, name, width, height)
  def print_data_amounts(self, data_list=[]):
    data_amouts = list(map(mapFn, data_list))
    pt = self.head
    while pt:
      for i, data in enumerate(data_list):
        if data == pt.data:
          data_amouts[i] += 1
      pt = pt.next
    
    for i, data in enumerate(data_list):
      print(str(data) + ' appears ' + str(data_amouts[i]) + ' times.')

    return 

linked_list = Exercise_linked_list(Node(15))
linked_list.ending_insert(5).ending_insert(10).ending_insert(5)

def print_linked_list_length():
  print("length: " + str(linked_list.length()))

def print_data_amounts():
  linked_list.print_data_amounts([5, 10, 15, 20])

def print_days():
  days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
  double_linked_list = Double_linked_list()
  for day in days:
    double_linked_list.add_node(Double_node(day))
  
  double_linked_list.print_from_head()