Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
brute_force_string_searching.cpp File Reference

String pattern search - brute force. More...

#include <iostream>
#include <cstring>
#include <vector>
Include dependency graph for brute_force_string_searching.cpp:

Namespaces

 

Functions

int string_search::brute_force (const std::string &text, const std::string &pattern)
 
int main ()
 

Variables

const std::vector< std::vector< std::string > > test_set
 

Detailed Description

String pattern search - brute force.

Function Documentation

◆ main()

int main ( void )

Main function

47 {
48 for (const auto &i : test_set) {
49 int output = brute_force(i[0], i[1]);
50
51 if (std::to_string(output) == i[2]) {
52 std::cout << "success\n";
53 } else {
54 std::cout << "failure\n";
55 }
56 }
57 return 0;
58}
const std::vector< std::vector< std::string > > test_set
Definition brute_force_string_searching.cpp:41
T to_string(T... args)
Here is the call graph for this function:

Variable Documentation

◆ test_set

const std::vector<std::vector<std::string> > test_set
Initial value:
= {
{"a", "aa", "-1"}, {"a", "a", "0"}, {"ba", "b", "0"},
{"bba", "bb", "0"}, {"bbca", "c", "2"}, {"ab", "b", "1"}}

set of test cases

41 {
42 // {text, pattern, expected output}
43 {"a", "aa", "-1"}, {"a", "a", "0"}, {"ba", "b", "0"},
44 {"bba", "bb", "0"}, {"bbca", "c", "2"}, {"ab", "b", "1"}};