MCPcopy Create free account
hub / github.com/careercup/ctci / partition

Function partition

python/Chapter 2/Question2_4.py:3–15  ·  view source on GitHub ↗
(linkedlist, x)

Source from the content-addressed store, hash-verified

1from classes.LinkedList import *
2
3def partition(linkedlist, x):
4 if linkedlist.head != None:
5 p1 = linkedlist.head
6 p2 = linkedlist.head.next
7 while p2 != None:
8 if p2.value < x:
9 p1.next = p2.next
10 p2.next = linkedlist.head
11 linkedlist.head = p2
12 p2 = p1.next
13 else:
14 p1 = p1.next
15 p2 = p1.next
16
17
18

Callers 1

Question2_4.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected