-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_split.cpp
More file actions
73 lines (57 loc) · 1.47 KB
/
test_split.cpp
File metadata and controls
73 lines (57 loc) · 1.47 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
CSCI 104: Homework 1 Problem 1
Use this file to test your split.cpp file.
Create linked lists and split them with your split() function.
You can compile this file like this:
g++ split.cpp test_split.cpp -o test_split
*/
#include "split.h"
#include <iostream>
#include<ostream>
using namespace std;
Node* create_in();
void printLL(Node* h);
int main(int argc, char* argv[])
{
Node* h = create_in();
Node* odds = nullptr;
Node* evens = nullptr;
cout << endl << "in" << endl;
printLL(h); // Print the original list after calling create_in()
split(h, odds, evens); // Uncomment this line to split the list into odds and evens
cout << endl << "odds" << endl;
printLL(odds);
cout << endl << "evens" << endl;
printLL(evens);
// Free the memory allocated for the nodes
Node* cur = h;
while (cur != nullptr) {
Node* temp = cur;
cur = cur->next;
delete temp;
}
return 0;
}
Node* create_in() {
Node* h = nullptr;
Node* cur = nullptr;
for (int i = 0; i < 1; i++) {
Node* new_node = new Node(i + 1, nullptr);
if (h == nullptr) {
h = new_node;
cur = h;
} else {
cur->next = new_node;
cur = new_node;
}
}
return h;
}
void printLL(Node* h) {
Node* current = h;
while (current != nullptr) {
std::cout << current->value << " ";
current = current->next;
}
std::cout << std::endl;
}