Skip to content
Snippets Groups Projects
Select Git revision
  • 7fb4f8d6fd89de0284c01293bb2e7fc643a7b86f
  • master default protected
  • gitkeep
  • dev protected
  • Issue/2449-GuidPidSlugToProjectSettings
  • Issue/2309-docs
  • Issue/2355-topLevelOrg
  • Issue/2328-noFailOnLog
  • Hotfix/2371-fixGitLabinRCV
  • Issue/2287-guestRole
  • Fix/xxxx-activateGitlab
  • Test/xxxx-enablingGitLab
  • Issue/2349-gitlabHttps
  • Issue/2259-updatePids
  • Issue/2101-gitLabResTypeUi
  • Hotfix/2202-fixNaNQuota
  • Issue/2246-quotaResoval
  • Issue/2221-projectDateCreated
  • Hotfix/2224-quotaSizeAnalytics
  • Fix/xxxx-resourceVisibility
  • Issue/2000-gitlabResourcesAPI
  • v4.4.3
  • v4.4.2
  • v4.4.1
  • v4.4.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
  • v4.3.0
  • v4.2.8
  • v4.2.7
  • v4.2.6
  • v4.2.5
  • v4.2.4
  • v4.2.3
  • v4.2.2
  • v4.2.1
  • v4.2.0
  • v4.1.1
  • v4.1.0
41 results

ProjectControllerTests.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    main.cpp 2.13 KiB
    #include <iostream>
    #include <unordered_map>
    #include <vector>
    #include <list>
    
    using namespace std;
    
    class Node;
    class Path;
    Path *bfs(int start, int end, int max, unordered_map<int, node> nodes);
    
    class Node {
        int year;
        Path* shortest_path;
    };
    
    class Path {
        vector<Node* > nodes;
    };
    
    
    int main()
    {
        cout << "Finding the shortest path from 2018 to 1889 using BFS" << endl;
    
        unordered_map<int, Node> nodes;
    
        Path* result = bfs(2018, 1889, 1000000000, nodes);
    
        for(int i=0; i < result->nodes.size()-1; i++)
        {
            cout << "Reise von " << result->nodes[i]->year << " nach " <<  result->nodes[i+1]->year;
        }
    
        return 0;
    }
    
    Path *bfs(int start, int end, int max, unordered_map<int, node> nodes)
    {
        //Generate a starting node
        Node start_node;
        nodes[start] = start_node;
        start_node.year = start;
    
        //Generate a path for the starting node
        Path start_path;
        start_path.nodes.push_back(&start_node);
    
        start_node.shortest_path = &start_path;
    
        list<Node* > queue;
    
        queue.push_back(&start_node);
    
        while (!queue.empty()) {
            //Get and check the first element from the queue
            Node *current_node = queue.front();
            queue.pop_front();
            if(current_node->year == end)
            {
                cout << "Target node found" << endl;
                return current_node->shortest_path;
            }
    
    
            int c_year = current_node->year;
            //Check the child nodes
            {
                if(c_year + 7 <= max)
                {
                    if(nodes.find(c_year + 7) == nodes.end())
                    {
                        //Generate child node
                        Node* child = new Node;
    
                        //Set correct year
                        child->year = c_year + 7;
    
                        //Copy over path
                        Path* child_path = new Path;
                        child_path->nodes = current_node->shortest_path->nodes;
                        child_path->nodes.push_back(child);
                        child->shortest_path = child_path;
                    }
                }
            }
    
            //Delete this path, as it will not be used anymore
            delete current_node->shortest_path;
        }
    }