Menu



Manage

Cord > Study_Algorithm 전체 다운로드
Study_Algorithm > 5/week05_06_chap04_09_self.py Lines 60 | 1.3 KB
다운로드

                        # week05_05_chap04_09.py

class Node:
    def __init__(self):
        self.data = None
        self.link = None


def print_nodes(start):
    current = start

    if current is None:
        return

    print(current.data, end=' ')
    while current.link is not None:
        current = current.link  # 가르키는 대상 증가
        print(current.data, end=' ')
    print()


def make_simple_linked_list(name_height):
    global head, current, pre
    print_nodes(head)

    node = Node()
    node.data = name_height

    if head is None:  # 첫 번째 노드일 때
        head = node
        return

    if head.data[1] < name_height[1]:
        node.link = head
        head = node
        return

    current = head
    while current.link is not None:
        pre = current
        current = current.link
        if current.data[1] < name_height[1]:
            pre.link = node
            node.link = current
            return

    current.link = node


head, current, pre = None, None, None
#data_array = ["다현", "정연", "쯔위", "사나", "지효"]
#data_array = ["백현", "시우민", "첸"]
data_array = [["지민", 180], ["정국", 177], ["뷔", 183], ["슈가", 175], ["진", 179]]


if __name__ == "__main__":
    for data in data_array:
        make_simple_linked_list(data)

    print_nodes(head)