-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllrec.cpp
More file actions
42 lines (31 loc) · 792 Bytes
/
llrec.cpp
File metadata and controls
42 lines (31 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "llrec.h"
//*********************************************
// Provide your implementation of llpivot below
//*********************************************
void llpivot(Node *&head, Node *&smaller, Node *&larger, int pivot){
if(head == nullptr){
larger = nullptr;
smaller = nullptr;
}
else if(head->next == nullptr){
if(head->val > pivot){
larger = head;
smaller = nullptr;
}
else if(head->val <= pivot){
smaller = head;
larger = nullptr;
}
head = nullptr;
}
else if(head->val > pivot){
larger = head;
head = head->next;
llpivot(head, smaller, larger->next, pivot);
}
else if(head->val <= pivot){
smaller = head;
head = head->next;
llpivot(head, smaller->next, larger, pivot);
}
}