2 jj314145738 jj314145738 于 2017.09.06 16:20 提问

求解决一个c++类调用的问题 5C
c++

class Random
{
private:
static int n;
static vector list;
static char file[STR_LEN];

public:
static void Build();
static void BuildFromFile();
static int GetNode(int i);
};
struct Edge
{
int u,v,c;
double w1,w2;
};

class Graph
{
private:
static int n;
static int m;
static vector degree;
static vector indegree;
static vector outdegree;
static void qsort_edges(int h, int t);

public:
static void QuickSort(int p,int r);
static int partion(int p,int r);
static void insertsort_edges(int right);
static void merge_edges(int start, int middle, int left);
static void mergesort_edges(int start, int end);
static void merge(int start, int middle, int end);
static bool built;
static vector index;
static vector correspond;
static void Build();
static int GetN();
static int GetM();
static vector edges;
static int GetDegree(int node);
static int GetOutDegree(int node);
static int GetInDegree(int node);
static int GetNeighbor(int node);
static Edge GetEdge(int node, int idx);
static void BuildIC();
static void BuildWC();
static void Build2GC();
static void Build2WC();
static void Build2DWC();
static void BuildFromFile2DWC(char *file); //directed graph + wic
static void BuildFromFile2OIC(char *file);
static void BuildFromFile2DUC(char *file, double p);//directed graph + uic
static void BuildFromFile2WC();// undirected graph + wic
static void BuildFromFile2UC(char *file, double p);//undirected graph + uic
static void Build2IC();
static void sortEdges();

/*
static void Build2DIC(double, double);
static void Build2RIC(double, double);
static void Build2TIC(double, double, double);
static void Build2DT(double, double, double);
static void Build2T(double, double, double);
*/
static void Stats();

};
bool Graph::built = false;
int Graph::n = 0;
int Graph::m = 0;
vector Graph::index;
vector Graph::degree(MAX_NODE,0);
vector Graph::indegree(MAX_NODE,0);
vector Graph::outdegree(MAX_NODE,0);
vector Graph::edges;
vector Graph::correspond(MAX_EDGE,0);
int main()
{
time_t t;
srand((unsigned) time(&t));

bool directed = false;
int R = 100;
 Graph graph1;
 printf("abc");
  graph1.BuildFromFile2WC();//注释处执行进不去该方法
  printf("abc");

}

void Graph::BuildFromFile2WC()

{
if (built)
return;
built = true;
printf("aa\n");
char filename[100] = "E:/newcode2/networks/hep.txt";
FILE* in = fopen(filename, "r");
fscanf(in,"%ld %ld", &n, &m);

degree.resize(n);
indegree.resize(n);
outdegree.resize(n);
edges.resize(2*m);
correspond.resize(2*m);

for (int i=0; i<m; i++)
{
    //scanf("%ld %ld", &edges[i].u, &edges[i].v);
    fscanf(in,"%ld %ld", &edges[i].u, &edges[i].v);
            //inverse
            //int temp = 0;
            //temp = edges[i].u;
            //edges[i].u = edges[i].v;
            //edges[i].v = temp;

    //edges[i].u;
    //edges[i].v;
    edges[i].w1=0;
    edges[i].w2=0;
    edges[i+m].u = edges[i].v;
    edges[i+m].v = edges[i].u;
    edges[i+m].w1=0;
    edges[i+m].w2=0;
    edges[i].c   = 1;
    edges[i+m].c = 1;
    degree[edges[i].u]++;
    degree[edges[i].v]++;
    indegree[edges[i].v]++;
    indegree[edges[i].u]++;
    outdegree[edges[i].u]++;
    outdegree[edges[i].v]++;
    correspond[i] = i+m;
    correspond[i+m] = i;
}

qsort_edges(0, 2*m-1);
int newlocation[MAX_EDGE] = {0};
int m1 = 0;
for (int i=1; i<2*m; i++)
{
    if ((edges[i].u != edges[m1].u) || (edges[i].v != edges[m1].v))
    {
        m1++;
        edges[m1] = edges[i];
    }
    else
    {
        edges[m1].c++;
        if (edges[i].w1<edges[m1].w1) edges[m1].w1=edges[i].w1;
        edges[m1].w2=min(edges[m1].w2,edges[i].w2);
        //if (edges[i].u==141 && edges[i].v==0) printf("%d %lg %lg %lg\n",i,edges[m1].w2,edges[i].w2,min(edges[m1].w2,edges[i].w2));
    }
    newlocation[i] = m1;
}

for(int i=0; i<2*m; i++){
    correspond[newlocation[i]] = newlocation[correspond[i]];
}

if (m!=0)
    m = m1+1;

index.resize(n);
for (int i=0; i<n; i++)
    index[i] = 0;
for (int i=0; i<m; i++)
    index[edges[i].u] = i;
for (int i=1; i<n; i++)
    if (index[i] < index[i-1])
        index[i] = index[i-1];

for (int i=0;i<m;i++)
{
    //if (edges[i].w1==0)
        edges[i].w1=-log(1-pow(1-1.0/indegree[edges[i].v], edges[i].c));
    //if (edges[i].w2==0)
        edges[i].w2=-log(1-pow(1-1.0/indegree[edges[i].u], edges[i].c));
}

//add temp
FILE *out = fopen("directed.txt", "w");
for (int i=0; i<m; i++){
    //if(indegree[edges[i].v]==0)
        //continue;
    fprintf(out, "%d\t%d\t%f\n", edges[i].u, edges[i].v, 1.0/indegree[edges[i].v]);
}

fclose(out);

}
执行main时候,第一个abc能输出,第二个输出不了,中间那个graph1.BuildFromFile2WC()执行不了,到那就结束了,怎么解决啊,求大神指点

3个回答

what951006
what951006   Rxr 2017.09.06 19:10

这个的话,你贴的太长了,如果有必要,我可以远程帮你

zhang_guyuan
zhang_guyuan   2017.09.07 16:23

你直接说什么错误就好啊,贴这么多代码谁有时间帮你看》》》》

fzuim
fzuim   2017.09.08 09:06

同意楼上,什么错误就说

Csdn user default icon
上传中...
上传图片
插入图片