def partition(ll, key): befLL = LinkedList() aftLL = LinkedList() keyLL = LinkedList() now = ll.head for _ in range(len(ll)): if now.value > key: aftLL.add(now.value) elif now.value == key: keyLL.add(now.value) elif now.value < key: befLL.add(now.value) now = now.next befLL.add_multiple(keyLL) befLL.add_multiple(aftLL) print(befLL)
from Chap2.LinkedList import LinkedList def deleteMiddle(node): #두 문장의 순서도 중요하다, 값 먼저 바꾸고 next 변경 node.value = node.next.value node.next = node.next.next ll = LinkedList() ll.add_multiple([1, 2, 3, 4]) middle_node = ll.add(5) ll.add_multiple([7, 8, 9]) print(ll) deleteMiddle(middle_node) print(ll) #헤드 접근 없이 삭제할 노드에만 접근이 가능하다는 것 / 나는 c에는 접근할 수 있다.