-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.cpp
More file actions
44 lines (33 loc) · 908 Bytes
/
split.cpp
File metadata and controls
44 lines (33 loc) · 908 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
43
44
/*
CSCI 104: Homework 1 Problem 1
Write a recursive function to split a sorted singly-linked
list into two sorted linked lists, where one has the even
numbers and the other contains the odd numbers. Students
will receive no credit for non-recursive solutions.
To test your program write a separate .cpp file and #include
split.h. **Do NOT add main() to this file**. When you submit
the function below should be the only one in this file.
*/
#include "split.h"
#include <cstddef>
/* Add a prototype for a helper function here if you need */
void split(Node*& in, Node*& odds, Node*& evens)
{
/* Add code here */
// WRITE YOUR CODE HERE
if (in==NULL){
return;
}
Node* curr=in;
in=in->next;
curr->next = NULL;
split(in, odds, evens);
if(curr->value %2==0){
curr->next = evens;
evens = curr;
}else{
curr->next=odds;
odds=curr;
}
}
/* If you needed a helper function, write it here */