53namespace median_search2 {
70 slowptr = slowptr->
next;
74 return (fastptr->
next) ? slowptr->
next : slowptr;
77void deleteAll(
const ListNode*
const head) {
79 deleteAll(head->next);
95 for (
int i = 2; i < 6; ++i) {
104 temp->
next =
nullptr;
106 const ListNode*
const median = search::median_search2::middleNode(head1);
107 assert(3 == median->
val);
108 search::median_search2::deleteAll(head1);
109 std::cout <<
"test case:1 passed\n";
116 for (
int i = 2; i < 7; ++i) {
125 temp2->
next =
nullptr;
127 const ListNode*
const median1 = search::median_search2::middleNode(head2);
128 assert(4 == median1->
val);
129 search::median_search2::deleteAll(head2);
130 std::cout <<
"test case:2 passed\n";
132 std::cout <<
"--All tests passed--\n";
ListNode()=default
default constructor
int val
the value stored in the node
ListNode(int x)
constructor with value for node->val provided
ListNode * next
pointer to the next node
ListNode(int x, ListNode *next)
constructor with values provided for node->val and node->next