Skip to content

Commit

Permalink
Fixes to examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedElashri committed Sep 7, 2023
1 parent 6644bbf commit 1022b76
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Jagged.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class JaggedArray {
data.push_back(newRow);
}

// Method to get data
const std::vector<std::vector<T>>& get_data() const {
return data;
}
// Method to get an element from a specific row and column
T get(int row, int col) const {
if (row < 0 || row >= data.size() || col < 0 || col >= data[row].size()) {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OBJ_DIR = $(SRC_DIR)/obj

# Mapping from source files to C++ standard
CPP11_SOURCES =
CPP17_SOURCES = JaggedArray stat reduction concanate boolean_fancy mask pad_none fill_none drop_none is_none
CPP17_SOURCES = JaggedArray stat reduction concanate boolean_fancy mask pad_none fill_none drop_none is_none sort
CPP23_SOURCES =

# Rule to build all examples
Expand Down
1 change: 0 additions & 1 deletion examples/drop_none.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include"../Jagged.h"
#include <optional>


int main() {
Expand Down
1 change: 0 additions & 1 deletion examples/fill_none.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include"../Jagged.h"
#include <optional>

int main() {
// Create a JaggedArray with some missing values
Expand Down
1 change: 0 additions & 1 deletion examples/is_none.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include"../Jagged.h"
#include <optional>



Expand Down
1 change: 0 additions & 1 deletion examples/mask.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include"../Jagged.h"
#include <optional>


int main() {
Expand Down
1 change: 0 additions & 1 deletion examples/pad_none.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include"../Jagged.h"
#include <optional>

int main() {
// Create a JaggedArray with some missing values
Expand Down
12 changes: 8 additions & 4 deletions examples/sort.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include"../Jagged.h"

int main() {
// Initialize a JaggedArray with integer type
JaggedArray<int> jaggedArray({{3, 1, 2}, {5, 4}, {9, 8, 7, 6}});
// Initialize a JaggedArray with std::optional<int> type
JaggedArray<std::optional<int>> jaggedArray({{3, 1, 2}, {5, 4}, {9, 8, 7, 6}});

// Print the original JaggedArray
std::cout << "Original JaggedArray: \n";
// (Assume a method print() exists in your JaggedArray class to print the jagged array)
jaggedArray.print();

// Sort each sub-array in ascending order
Expand All @@ -21,7 +20,12 @@ int main() {

// Print the sorted indices
std::cout << "Sorted Indices: \n";
sortedIndices.print();
for (const auto& row : sortedIndices.get_data()) {
for (const auto& element : row) {
std::cout << element << ' ';
}
std::cout << '\n';
}

return 0;
}

0 comments on commit 1022b76

Please sign in to comment.