Can't create map<string, set<int> >

-1

I am attempting to implement kruskal's algorithm. I am having troubles generating a map. My map type is

map<int, set<int> > kruskal;

I can't initialize it though. I get an exception thrown:

Exception thrown at 0x0033F85C in ShortPath.exe: 0xC0000005: Access violation executing location 0x0033F85C.

I don't know what to do next.

I tried initializing like this:

typedef map< int, std::set<int> > mapType;
mapType kruskal;

and it didn't work. In the code below, I am certain MinHeap2 works. I can print out all of the arcs when I do not have a map. As soon as i add a map my program crashes.

#include <iostream>
#include "MinHeap2.h"
#include <cstdlib>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

void processString( int size, string line, MinHeap2 &arcs) {
    istringstream ss(line);

    bool first = true;

    int source;
    int sink;
    int length;

    string input;
    while (ss >> input) {
        if (first) {
            source = stoi(input);
            first = false;
        }
        else {
            int pos = input.find(",");
            sink = stoi(input.substr(0, pos));
            length = stoi(input.substr(pos + 1));
            arcs.insert(source, sink, length);
        }
    }
}

void createList( int size, string file, MinHeap2& arcs) {
    ifstream inFile;
    inFile.open(file);
    if (!inFile) {
        exit(1);
    }
    string line;
    while (!inFile.eof()) {
        getline(inFile, line);
        processString(size, line, arcs);
    }
    inFile.close();
}

int main() {
    int size = 200;
    string file = "Data.txt";

    typedef std::set<int> sets;

    std::map<int, sets> myMap = map<int, set<int> >();

    MinHeap2 arcs = MinHeap2(3735);

    createList(size, file, arcs);

    //for (int i = 1; i < 201; i++) {
    //sets s;
        //if (kruskal.find(i) == kruskal.end()) {
        //  kruskal[i] = s;
        //}
    //}

    while (!arcs.isEmpty()) {
        int source = arcs.peekStart();
        int dest = arcs.peekDest();
        vector<int> intersection;
        //set_intersection(kruskal[source].begin(), kruskal[source].end(), kruskal[dest].begin(), kruskal[dest].end(), std::back_inserter(intersection));
        if (intersection.size() == 0) {
            //unionize(kruskal, source, dest);

            cout << source << "->" << dest << ": " << arcs.dequeuDist() << endl;
        }
    }
}

I get an exception thrown in xtree():

~_Tree() noexcept { // destroy tree
    _Get_data()._Erase_head(_Getal());
#if _ITERATOR_DEBUG_LEVEL != 0
    auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
    _Delete_plain(_Alproxy, _Get_data()._Myproxy);
#endif /* _ITERATOR_DEBUG_LEVEL != 0 */
}

As an example for Data.txt here is a shortened test version:

    1   2,1 8,2
    2   1,1 3,1
    3   2,1 4,1
    4   3,1 5,1
    5   4,1 6,1
    6   5,1 7,1
    7   6,1 8,1
    8   7,1 1,2

Also, I am new to stack overflow. Sorry if I keep not including everything. I do not now how to easily include all my code.

c++
dictionary
asked on Stack Overflow Jul 31, 2019 by Julio Alvarado • edited Aug 1, 2019 by Julio Alvarado

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0