mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
test cases docs added, merge fixed
This commit is contained in:
parent
ccc26cf891
commit
be0160b415
@ -47,15 +47,41 @@ struct Node {
|
||||
};
|
||||
|
||||
/**
|
||||
* @namespace search
|
||||
* @brief Searching algorithms
|
||||
* */
|
||||
namespace search {
|
||||
* @brief A simple function to print the linked list
|
||||
* @param start The head of the linked list
|
||||
* @returns void
|
||||
*/
|
||||
void printLinkedList(Node *start) {
|
||||
while (start != nullptr) {
|
||||
std::cout << "->" << start->data;
|
||||
start = start->next;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @namespace sublist_search
|
||||
* @brief Functions for the [Sublist Search](https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list) implementation
|
||||
* */
|
||||
namespace sublist_search {
|
||||
* @brief Makes a dummy linked list for testing.
|
||||
* @param data A vector of "int" containing the data that is supposed to be
|
||||
* stored in nodes of linked list.
|
||||
* @returns Node* A head pointer to the linked list.
|
||||
*/
|
||||
Node *makeLinkedList(const std::vector<uint64_t> &data) {
|
||||
Node *head = nullptr;
|
||||
Node *tail = nullptr;
|
||||
for (int i : data) {
|
||||
Node *node = new Node;
|
||||
node->data = i;
|
||||
node->next = nullptr;
|
||||
if (head == nullptr) {
|
||||
head = node;
|
||||
tail = node;
|
||||
} else {
|
||||
tail->next = node;
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main searching function
|
||||
@ -110,44 +136,7 @@ namespace search {
|
||||
} // namespace sublist_search
|
||||
} // namespace search
|
||||
|
||||
/**
|
||||
* @brief A simple function to print the linked list
|
||||
* @param start The head of the linked list
|
||||
* @returns void
|
||||
*/
|
||||
void printLinkedList(Node *start) {
|
||||
while (start != nullptr) {
|
||||
std::cout << "->" << start->data;
|
||||
start = start->next;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Makes a dummy linked list for testing.
|
||||
* @param data A vector of "int" containing the data that is supposed to be
|
||||
* stored in nodes of linked list.
|
||||
* @returns Node* A head pointer to the linked list.
|
||||
*/
|
||||
Node *makeLinkedList(const std::vector<uint64_t> &data) {
|
||||
Node *head = nullptr;
|
||||
Node *tail = nullptr;
|
||||
for (int i : data) {
|
||||
Node *node = new Node;
|
||||
node->data = i;
|
||||
node->next = nullptr;
|
||||
if (head == nullptr) {
|
||||
head = node;
|
||||
tail = node;
|
||||
} else {
|
||||
tail->next = node;
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
return head;
|
||||
}
|
||||
} // namespace sublist_search
|
||||
} // namespace search
|
||||
|
||||
/**
|
||||
* @brief class encapsulating the necessary test cases
|
||||
|
Loading…
Reference in New Issue
Block a user