0
我一直在努力,包括在C C IGRAPH庫++(基於Eclipse),如果你對此有何評論print_vectorList(&vn1, stdout)
你打印igraph_vector_ptr_t(igraph_vector_t向量的列表)
cout<<VECTOR(v2)[0]<<endl------------>3
cout<<VECTOR(v2)[1]<<endl------------>7
此代碼的工作好,如果你不」牛逼評論print_vectorList(& VN1,標準輸出),你會得到
0 1 4 9
1 0 7 9
2 3 5 9
3 2 6 9
4 0 5 8
5 2 4 8
6 3 7 8
7 1 6 8
8 4 5 6 7
9 0 1 2 3
與
cout<<VECTOR(v2)[0]<<endl------------>0
cout<<VECTOR(v2)[1]<<endl------------>0
怎麼了?
#include <igraph.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;
void print_vector(igraph_vector_t *v, FILE *f) {
long int i;
for (i=0; i<igraph_vector_size(v); i++) {
fprintf(f, " %li", (long int) VECTOR(*v)[i]);
}
fprintf(f, "\n");
}
void print_vectorList(igraph_vector_ptr_t * vl, FILE *f) {
long int i,n;
n = igraph_vector_ptr_size(vl);
for (i=0; i<n; i++) {
igraph_vector_t * vt;
vt=(igraph_vector_t*)igraph_vector_ptr_e(vl,i);
print_vector((igraph_vector_t*)vt,f);
igraph_vector_destroy(vt);
free(vt);
}
}
long int GetElementVectorList(igraph_vector_ptr_t vl,long int i,long int j) {
igraph_vector_t * vt;
vt=(igraph_vector_t*)igraph_vector_ptr_e(&vl,i);
return(VECTOR(*(igraph_vector_t*)vt)[j]);
}
int main() {
igraph_t g;
igraph_vector_t v;
igraph_vector_init(&v,32);
VECTOR(v)[0]=0; VECTOR(v)[1]=1;
VECTOR(v)[2]=0; VECTOR(v)[3]=4;
VECTOR(v)[4]=0; VECTOR(v)[5]=9;
VECTOR(v)[6]=1; VECTOR(v)[7]=7;
VECTOR(v)[8]=1; VECTOR(v)[9]=9;
VECTOR(v)[10]=2; VECTOR(v)[11]=9;
VECTOR(v)[12]=2; VECTOR(v)[13]=3;
VECTOR(v)[14]=2; VECTOR(v)[15]=5;
VECTOR(v)[16]=3; VECTOR(v)[17]=6;
VECTOR(v)[18]=3; VECTOR(v)[19]=9;
VECTOR(v)[20]=4; VECTOR(v)[21]=5;
VECTOR(v)[22]=4; VECTOR(v)[23]=8;
VECTOR(v)[24]=5; VECTOR(v)[25]=8;
VECTOR(v)[26]=6; VECTOR(v)[27]=7;
VECTOR(v)[28]=6; VECTOR(v)[29]=8;
VECTOR(v)[30]=7; VECTOR(v)[31]=8;
igraph_create(&g, &v, 0,0);
// Neighbors
igraph_vector_ptr_t vn1;
igraph_vs_t vs;
igraph_vector_ptr_init(&vn1, 0);
igraph_vs_vector_small(&vs, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
igraph_neighborhood(&g, &vn1,vs, 1, IGRAPH_OUT);
print_vectorList(&vn1, stdout); // **comment here and.....**
igraph_vector_t v2;
igraph_vector_init(&v2,2);
VECTOR(v2)[0]=GetElementVectorList(vn1,6,1); VECTOR(v2)[1]=GetElementVectorList(vn1,6,2);
cout<<VECTOR(v2)[0]<<endl; // **you can get a good result here**
cout<<VECTOR(v2)[1]<<endl;
igraph_destroy(&g);
igraph_vector_destroy(&v);
igraph_vector_ptr_destroy_all(&vn1);
igraph_vs_destroy(&vs);
igraph_vector_destroy(&v2);
return 0;
}
看來,功能打印發生了一些事情,但我不知道發生了什麼。
在此先感謝
vacing
你可以發佈一個[** minimal ** test-case](http://sscce.org)嗎? – 2012-04-19 09:53:29
尋找內存損壞。檢查valgrind。 – 2012-04-19 09:55:31
好吧,我發佈了所有程序 – user1310873 2012-04-19 10:22:07