An open API service indexing awesome lists of open source software.

https://github.com/shahrzadabedi/currencyconverter

A currency converter that can be configured with different exchange rates and converts the currency symbols using a BFS algorithm
https://github.com/shahrzadabedi/currencyconverter

algorithms bfs-algorithm

Last synced: 4 months ago
JSON representation

A currency converter that can be configured with different exchange rates and converts the currency symbols using a BFS algorithm

Awesome Lists containing this project

README

        

In the Currency Converter project, we have an interface that lets us configure, convert and clear exchange rates:
```
public interface ICurrencyConverter
{
void ClearConfiguration();

void UpdateConfiguration(IEnumerable> conversionRates);

double Convert(string fromCurrency, string toCurrency, double amount);
}
```

I used BFS algorithm to traverse the graph. To represent the graph, I make an adjacency list for each vertex using BuildAdjacencyLists() method in
BfsShortestPathProvider class that implements IShortestPathProvider interface.

* UpdateConfiguration method:
It adjusts and sets up adjacency lists for all vertices and also makes a vertices list for later check.
The Convert method first traverses the whole graph using BFS algorithm. Meanwhile it builds a dictionary that
keeps (the parent of each vertex, the cost to reach the parent, the cost to reach the current vertex).
After the whole graph is traversed it then uses this dictionary and starts from destination verex to finally reach the source vertex.

* ClearConfiguration method:
This method clears all adjustments.

* UpdateConfiguration method:
This method sets up the adjacency lists and the list of vertices for later traversal.