File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed
operations_on_datastructures Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 61
61
submodules : true
62
62
- run : |
63
63
cmake -B ./build -S .
64
- cmake --build build
64
+ cmake --build build --parallel 4
65
65
- name : Label on PR fail
66
66
uses : actions/github-script@v6
67
67
if : ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ namespace math {
46
46
*/
47
47
uint64_t iterativeFactorial (uint8_t n) {
48
48
if (n > 20 ) {
49
- throw new std::invalid_argument (" Maximum n value is 20" );
49
+ throw std::invalid_argument (" Maximum n value is 20" );
50
50
}
51
51
52
52
// 1 because it is the identity number of multiplication.
@@ -101,12 +101,14 @@ static void test() {
101
101
std::cout << " Exception test \n "
102
102
" Input: 21 \n "
103
103
" Expected output: Exception thrown \n " ;
104
+
105
+ bool wasExceptionThrown = false ;
104
106
try {
105
107
math::iterativeFactorial (21 );
106
- } catch (std::invalid_argument* e) {
107
- std::cout << " Exception thrown successfully \n Content: " << e->what ()
108
- << " \n " ;
108
+ } catch (const std::invalid_argument&) {
109
+ wasExceptionThrown = true ;
109
110
}
111
+ assert (wasExceptionThrown);
110
112
111
113
std::cout << " All tests have passed successfully.\n " ;
112
114
}
Original file line number Diff line number Diff line change @@ -16,6 +16,20 @@ int getSize(Node *root) {
16
16
return 1 + getSize (root->next );
17
17
}
18
18
19
+ /*
20
+ * @brief This function dealocates memory related to the given list
21
+ * It recursively deletes all of the nodes of the input list.
22
+ * @param room the root/head of the input list
23
+ * @warning Plese note that the memory for each node has to be alocated using new.
24
+ */
25
+ void deleteList (Node *const root) {
26
+ if (root != NULL )
27
+ {
28
+ deleteList (root->next );
29
+ delete root;
30
+ }
31
+ }
32
+
19
33
int main () {
20
34
Node *myList = new Node (0 , NULL ); // Initializes the LinkedList
21
35
Node *temp = myList;
@@ -31,6 +45,8 @@ int main() {
31
45
std::cout << getSize (myList) << std::endl
32
46
<< getSize (secondList) << std::endl
33
47
<< getSize (thirdList) << std::endl;
48
+ deleteList (secondList);
49
+ deleteList (myList);
34
50
35
51
return 0 ;
36
52
}
You can’t perform that action at this time.
0 commit comments