mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-09 15:43:48 +08:00
test cases docs added, merge fixed
This commit is contained in:
@@ -37,25 +37,51 @@ namespace search {
|
|||||||
* Search](https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list)
|
* Search](https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list)
|
||||||
* implementation
|
* implementation
|
||||||
*/
|
*/
|
||||||
namespace sublist_search {
|
namespace sublist_search {
|
||||||
/**
|
/**
|
||||||
* @brief A Node structure representing a single link Node in a linked list
|
* @brief A Node structure representing a single link Node in a linked list
|
||||||
*/
|
*/
|
||||||
struct Node {
|
struct Node {
|
||||||
uint32_t data = 0;
|
uint32_t data = 0;
|
||||||
Node *next{};
|
Node *next{};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @namespace search
|
|
||||||
* @brief Searching algorithms
|
|
||||||
* */
|
|
||||||
namespace search {
|
|
||||||
/**
|
/**
|
||||||
* @namespace sublist_search
|
* @brief A simple function to print the linked list
|
||||||
* @brief Functions for the [Sublist Search](https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list) implementation
|
* @param start The head of the linked list
|
||||||
* */
|
* @returns void
|
||||||
namespace sublist_search {
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Main searching function
|
* @brief Main searching function
|
||||||
@@ -110,44 +136,7 @@ namespace search {
|
|||||||
} // namespace sublist_search
|
} // namespace sublist_search
|
||||||
} // namespace 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
|
* @brief class encapsulating the necessary test cases
|
||||||
|
|||||||
Reference in New Issue
Block a user