File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed
Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 44Output: 3 -> 1 -> 2 -> 10 -> 5 -> 5 -> 8
55"""
66
7+ from LL_implementation import LLNode , LinkedList
8+
9+ def partition (ll , x ):
10+ partitioned = LinkedList ()
11+ current = ll .head
12+ while current .next :
13+ if current .data >= x :
14+ partitioned .add (current .data )
15+ else :
16+ partitioned .insert_at_head (current .data )
17+ current = current .next
18+ if current .data >= x :
19+ partitioned .add (current .data )
20+ else :
21+ partitioned .insert_at_head (current .data )
22+ return partitioned
723
824
925
1026
1127if __name__ == "__main__" :
12- print "nothing yet"
28+ ll = LinkedList ()
29+ ll .add (3 )
30+ ll .add (5 )
31+ ll .add (8 )
32+ ll .add (5 )
33+ ll .add (10 )
34+ ll .add (2 )
35+ ll .add (1 )
36+
37+ new_ll = partition (ll , 5 )
38+ new_ll ._print () #remember that x itself can be anywhere in the second half of the output ll
39+
You can’t perform that action at this time.
0 commit comments