Skip to content

Commit 3f8aecb

Browse files
authored
Merge branch 'master' into properly_evaluate_GITHUB_ACTOR
2 parents 2f19756 + 519d37f commit 3f8aecb

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

.github/workflows/awesome_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
submodules: true
6262
- run: |
6363
cmake -B ./build -S .
64-
cmake --build build
64+
cmake --build build --parallel 4
6565
- name: Label on PR fail
6666
uses: actions/github-script@v6
6767
if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}

math/iterative_factorial.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace math {
4646
*/
4747
uint64_t iterativeFactorial(uint8_t n) {
4848
if (n > 20) {
49-
throw new std::invalid_argument("Maximum n value is 20");
49+
throw std::invalid_argument("Maximum n value is 20");
5050
}
5151

5252
// 1 because it is the identity number of multiplication.
@@ -101,12 +101,14 @@ static void test() {
101101
std::cout << "Exception test \n"
102102
"Input: 21 \n"
103103
"Expected output: Exception thrown \n";
104+
105+
bool wasExceptionThrown = false;
104106
try {
105107
math::iterativeFactorial(21);
106-
} catch (std::invalid_argument* e) {
107-
std::cout << "Exception thrown successfully \nContent: " << e->what()
108-
<< "\n";
108+
} catch (const std::invalid_argument&) {
109+
wasExceptionThrown = true;
109110
}
111+
assert(wasExceptionThrown);
110112

111113
std::cout << "All tests have passed successfully.\n";
112114
}

operations_on_datastructures/get_size_of_linked_list.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ int getSize(Node *root) {
1616
return 1 + getSize(root->next);
1717
}
1818

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+
1933
int main() {
2034
Node *myList = new Node(0, NULL); // Initializes the LinkedList
2135
Node *temp = myList;
@@ -31,6 +45,8 @@ int main() {
3145
std::cout << getSize(myList) << std::endl
3246
<< getSize(secondList) << std::endl
3347
<< getSize(thirdList) << std::endl;
48+
deleteList(secondList);
49+
deleteList(myList);
3450

3551
return 0;
3652
}

sorting/counting_sort.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ int *Counting_Sort(int Arr[], int N) {
2727
int *Sorted_Arr = new int[N];
2828

2929
int *Count = new int[max - min + 1];
30+
for (int i = 0; i < max - min + 1; ++i) {
31+
Count[i] = 0;
32+
}
3033

3134
for (int i = 0; i < N; i++) Count[Arr[i] - min]++;
3235

@@ -37,6 +40,7 @@ int *Counting_Sort(int Arr[], int N) {
3740
Count[Arr[i] - min]--;
3841
}
3942

43+
delete[] Count;
4044
return Sorted_Arr;
4145
}
4246

@@ -51,6 +55,7 @@ int main() {
5155
Sorted_Arr = Counting_Sort(Arr, N);
5256
cout << "\n\t Sorted Array = ";
5357
Print(Sorted_Arr, N);
58+
delete[] Sorted_Arr;
5459
cout << endl;
5560

5661
return 0;

sorting/library_sort.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ void librarySort(int *index, int n) {
6969
index_pos_for_output++;
7070
}
7171
}
72+
delete[] numbered;
73+
delete[] gaps;
74+
for (int i = 0; i < 2; ++i) {
75+
delete[] library[i];
76+
}
7277
}
7378

7479
int main() {

0 commit comments

Comments
 (0)