File tree Expand file tree Collapse file tree 1 file changed +19
-26
lines changed
Python/chapter02/2.4 - Partition Expand file tree Collapse file tree 1 file changed +19
-26
lines changed Original file line number Diff line number Diff line change @@ -81,30 +81,23 @@ def remove_node(self,data):
81
81
prev .next = curr .next
82
82
curr = None
83
83
84
- def merge_link (self ,NodesA ,NodesB ):
85
-
86
- while NodesA is not None :
87
- Nodec = Node ()
88
-
89
-
90
84
def partition (self ,num ):
91
-
85
+ #llist_A and llist_b to be continers
86
+ llist_A = linklist ()
87
+ llist_B = linklist ()
88
+ head_A = llist_A .head
89
+ head_B = llist_B .head
92
90
curr = self .head
91
+ # Idea: Make two seperate llink and smash them together
93
92
while curr is not None :
94
- if (curr .data > num ):
95
- smallNodes = self .push (curr .data )
96
- curr = curr .next
93
+ if curr .data <= num :
94
+ llist_A .push (curr .data )
97
95
else :
98
- lagreNodes = self . (curr .data )
99
- curr = curr .next
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
96
+ llist_B .push (curr .data )
97
+ while head_B is not None :
98
+ llist_A .push (head_B .data )
99
+ head_B = head_B .next
100
+ llist_A .printList ()
108
101
109
102
110
103
@@ -115,15 +108,15 @@ def partition(self,num):
115
108
116
109
117
110
llist = linklist ()
118
- llist .push (1 )
119
- llist .push (2 )
120
111
llist .push (3 )
121
- llist .push (4 )
122
112
llist .push (5 )
123
- llist .push (6 )
113
+ llist .push (8 )
114
+ llist .push (5 )
115
+ llist .push (10 )
116
+ llist .push (2 )
117
+ llist .push (1 )
124
118
llist .printList ()
125
119
llist .lenght ()
120
+ llist .partition (5 )
126
121
127
- llist .Delete_Middle_Node ()# 3 should be removed
128
- llist .printList ()
129
122
llist .lenght ()
You can’t perform that action at this time.
0 commit comments