Probleme de new, tableau, * , ou & ?
|
Thread Tools
![]() |
Display Modes
![]() |
|
#1
|
|||
|
|||
Probleme de new, tableau, * , ou & ?
Probleme de new, tableau, * , ou & ?
bonjour j'ai un programme qui doit calculer les + courts chemins entre 1pt et 1 autre pt d'un graphe. ce graphe est modélisé dans un fichier texte que je place en paramètre quand je lance le programme. le parcours du fichier , et la récupération (l'affichage) des données se passe très bien ça coince quand je veux stocker tt ça dans un tableau précisément un tableau de Vertex (sommets) je fais Vertex *tabVertex = new Vertex[getNbreVert()]; et ensuite après chaque bloc d'information concernant chaque sommet je fais tabVertex[ligne] = new Vertex ( etiq , degre, x,y ); et ça provoque une erreur de pointeur je ne comprends pas pkoi, qq1 peut me dire ce qu'il manque pour que ça fonctionne svp? ensuite , ya 2 ou 3 autres endroits où des erreurs du même genre sont lancées, j'ai mis : // MERDE pour les marquer mais déjà si vous pouvez m'expliquer pourquoi la ligne du dessus marche pas , je pourrai ptêtre me débrouiller pour le reste. voici en partie le code du main, je mets des liens pour le code complet à la fin du post : /////////////////////////// Code:
//************************************************************************** int getNbreVert(); // return nbreVert void setNbreVert(int nbre); float distanceE(Vertex* ori, Vertex* extrem); void placementLigne (char * filename , int l); // pointer sur une ligne void Read_Graph (char *filename,AdjList& G,HashTable& T,int is_nondirectional); int Get_Source(HashTable& T); void Read_Dest (int source, Vertex *V, AdjList& G, HashTable& T); //************************************************************************** int vert ; char * fichiergraphe; //************************************************************************** int main (int argc, char *argv[]) { if (argc != 2) { cerr << "Syntax: " << argv[0] << " <graph-file>" << endl; exit(-1); } HashTable T(SIZE); // Hash Table for Vertices AdjList G(SIZE); // Graph as an Adjency List representation if (IS_NONDIRECTIONAL) cout << "Reading NON-DIRECTIONAL Graph..." << endl; else cout << "Reading DIRECTIONAL Graph (digraph)..." << endl; fichiergraphe = argv[1]; Read_Graph(fichiergraphe,G,T,IS_NONDIRECTIONAL); // Read the Graph int edges = G.no_of_edges(); ........ cout << endl << endl; cout << "EOF character pressed ! Exiting.............." << endl; } // ************************************************************************* int getNbreVert () { return vert; } void setNbreVert(int nbre) { vert = nbre; } //************************************************************************** void Read_Graph (char *filename,AdjList& G,HashTable& T,int is_nondirectional) { ifstream inp(filename); char buf[BUF_SIZE]; int etiq, degre; float x,y; if (!inp) { cerr << "Invalid filename \"" << filename << "\" !!" << endl; cerr << "Exiting........." << endl; exit(-1); } if (inp.getline(buf,BUF_SIZE) && inp.good()) { cout << "NBRE DE POINTS = " << buf << endl; setNbreVert(atoi(buf)); } // recupérer nombre de vert // on va y stocker nos vertex , avec le min d'infos // MERDE Vertex *tabVertex = new Vertex[getNbreVert()]; // on est à la 2nd ligne for (int ligne=0 ; ligne < getNbreVert() ; ligne++) { for ( int i=0 ; i<4 ; i++) { inp.getline(buf,BUF_SIZE); switch(i) { case 0: etiq = atoi(buf); break; case 1: degre = atoi(buf); break; case 2: x = atof(buf); break; case 3: y = atof(buf); break; } } cout << "Sommet="<< etiq << " degre=" << degre << " x=" << x << " y=" << y << endl; // MERDE tabVertex[ligne] = new Vertex ( etiq , degre, x,y ); } /* là on est dans la 2nd partie, où on doit récupérer l'étiquette des voisins de chaque sommet */ int vertB; for (int i=0 ; i<getNbreVert() ; i++) { inp.getline(buf,BUF_SIZE); degre = atoi ( buf); // on recupere le degre du sommet i cout << "Sommet i=" << i << " de degre=" << degre << endl; for (int j=0 ; j<degre ; j++) { inp.getline(buf,BUF_SIZE); vertB = atoi(buf); cout << " => voisin" << (j+1) << " = " << vertB << endl; // MERDE GRAVE G.add_edge( i, vertB, distanceE(tabVertex[i], tabVertex[vertB])); //cout << "TEST !!! tabVertex[i].getAbscisse()=" << tabVertex[i].getAbscisse() << endl; // MERDE cout << "distance entre [" << i <<";" << vertB <<"]=" << distanceE(tabVertex[i],tabVertex[vertB]) << endl; // on zap (pour l'instant?) les 3 autres lignes concernant vertB: degre, X,Y for (int k=0 ; k<3 ; k++) inp.getline(buf,BUF_SIZE); } } return; } // MERDE float distanceE(Vertex* ori, Vertex* extrem) { float X = ori->getAbscisse() - extrem->getAbscisse(); //cout << "X=" << X << endl; float Y = ori->getOrdonnee() - extrem->getOrdonnee(); //cout << "Y=" << Y << endl; float distanceEuclidienne = sqrt(pow(fabsf(X),2)+pow(fabsf(Y),2)); return distanceEuclidienne; } //************************************************************************** int Get_Source(HashTable& T){int source;char buf[BUF_SIZE];return source;} //************************************************************************** void Read_Dest (int source, Vertex *V, AdjList& G, HashTable& T){char buf[BUF_SIZE];} //************************************************************************** voici le code de http://small.axe.free.fr/graphe/ et principalement http://small.axe.free.fr/graphe/main.cc http://small.axe.free.fr/graphe/vertex.h http://small.axe.free.fr/graphe/adjlist.cc // je l'utilise pour ajouter les arètes : G.add_edge(..) |
Bookmarks |
«
Previous Thread
|
Next Thread
»
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Petit probléme avec outlook express !!! | Alexlesioux | Internet, Réseaux et Sécurité | 11 | 31-08-2004 07:16 |
Probleme de Raid avec MSI K7T266 Pro2 RU | Lionel-78 | Windows NT4/2000/XP Client | 0 | 03-04-2003 12:01 |
Probléme de lenteurs... | chalouf | Discussions sur le site et/ou le forum | 11 | 22-01-2003 19:37 |
Probleme site!! | chalouf | Discussions sur le site et/ou le forum | 4 | 21-10-2002 21:06 |
Problème forum | claude922 | Discussions sur le site et/ou le forum | 15 | 21-10-2002 07:04 |
All times are GMT +2. The time now is 13:50.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.