Skip to content

Commit

Permalink
removed unnecessary stuff & experimenting with idea of naming vector …
Browse files Browse the repository at this point in the history
…elements
  • Loading branch information
Konrad1991 committed Jul 24, 2024
1 parent 680cc5c commit 1fd466e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
48 changes: 48 additions & 0 deletions .development/Naming.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <vector>
#include <string>
#include <unordered_map>
#include <iostream>

class NamedVector {
private:
std::vector<double> values;
std::unordered_map<std::string, size_t> name_to_index;

public:
// Add an element with a name
void add_element(const std::string& name, double value) {
values.push_back(value);
name_to_index[name] = values.size() - 1;
}

// Get element by name
double get_element(const std::string& name) const {
auto it = name_to_index.find(name);
if (it != name_to_index.end()) {
return values[it->second];
}
throw std::runtime_error("Name not found");
}

// Display all elements and their names
void display() const {
for (const auto& pair : name_to_index) {
std::cout << pair.first << ": " << values[pair.second] << std::endl;
}
}
};

int main() {
NamedVector nv;
nv.add_element("a", 1.0);
nv.add_element("b", 2.0);
nv.add_element("c", 3.0);

std::cout << "Element 'b': " << nv.get_element("b") << std::endl;

std::cout << "All elements:" << std::endl;
nv.display();

return 0;
}

41 changes: 0 additions & 41 deletions src/cApproach/cApproach.c

This file was deleted.

0 comments on commit 1fd466e

Please sign in to comment.