mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fix: Requested changes made
This commit is contained in:
parent
463fcbcdb1
commit
18abc561d5
@ -17,15 +17,15 @@
|
|||||||
* Definition for singly-linked list.
|
* Definition for singly-linked list.
|
||||||
*/
|
*/
|
||||||
struct ListNode {
|
struct ListNode {
|
||||||
int val;
|
int val; // The value stored in the node
|
||||||
ListNode *next;
|
ListNode *next; // Pointer to the next node
|
||||||
ListNode() : val(0), next(nullptr) {}
|
ListNode() : val(0), next(nullptr) {} // Default constructor
|
||||||
ListNode(int x) : val(x), next(nullptr) {}
|
ListNode(int x) : val(x), next(nullptr) {} // Constructor with value for node->val provided
|
||||||
ListNode(int x, ListNode *next) : val(x), next(next) {}
|
ListNode(int x, ListNode *next) : val(x), next(next) {} // Constructor with values provided for node->val and node->next
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream> // for IO operations
|
||||||
#include <cassert>
|
#include <cassert> // for assert in tests
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace search
|
* @namespace search
|
||||||
@ -91,10 +91,10 @@ static void test() {
|
|||||||
delete head;
|
delete head;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListNode* head = new ListNode;
|
head = new ListNode;
|
||||||
head->val = 1;
|
head->val = 1;
|
||||||
|
|
||||||
ListNode* temp1 = head;
|
temp1 = head;
|
||||||
for(int i = 1; i < 7; ++i)
|
for(int i = 1; i < 7; ++i)
|
||||||
{
|
{
|
||||||
ListNode* temp2 = new ListNode;
|
ListNode* temp2 = new ListNode;
|
||||||
@ -104,7 +104,7 @@ static void test() {
|
|||||||
temp1 = temp2;
|
temp1 = temp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListNode* median = search::median_search2::middleNode(head);
|
median = search::median_search2::middleNode(head);
|
||||||
assert(4 == median->val); // 3 is the value of the median node.
|
assert(4 == median->val); // 3 is the value of the median node.
|
||||||
std::cout << "test case:1 passed\n";
|
std::cout << "test case:1 passed\n";
|
||||||
|
|
||||||
@ -114,6 +114,7 @@ static void test() {
|
|||||||
ListNode* t = head->next;
|
ListNode* t = head->next;
|
||||||
delete head;
|
delete head;
|
||||||
}
|
}
|
||||||
|
std::cout << "test case:2 passed\n";
|
||||||
std::cout << "--All tests passed--\n";
|
std::cout << "--All tests passed--\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user