473,410 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Graph ADT

21
Could you please find the bug in the following program which uses an edge-list implementation of graph adt:
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<vector>
  4. using namespace std;
  5. class vertice{
  6.     vector<class edge*> E;
  7. public:
  8.     void setEdge(class edge* e)
  9.     {
  10.         E.push_back(e);
  11.     }
  12.     int deg()
  13.     {
  14.         return E.size();
  15.     }
  16.     vector<class edge*> getE()
  17.     {
  18.         return E;
  19.     }
  20. };
  21. class edge{
  22.     vertice* V[2];
  23. public:
  24.     edge(vertice* v1,vertice* v2)
  25.     {
  26.         V[0]=v1;
  27.         V[1]=v2;
  28.     }
  29.     void setVertice(vertice* v1,vertice* v2)
  30.     {
  31.         V[0]=v1;
  32.         V[1]=v2;
  33.     }
  34.     vertice** getV()
  35.     {
  36.         return V;
  37.     }
  38. };
  39. class graph{
  40.     vector<vertice* > lv;
  41.     vector<edge* > le;
  42. public:
  43.     graph(int v,int e)
  44.     {
  45.         lv=vector<vertice*>(v);
  46.         le=vector<edge*>(e);
  47.     }
  48.     int numV()
  49.     {
  50.         return lv.size();
  51.     }
  52.     int numE()
  53.     {
  54.         return le.size();
  55.     }
  56.     void insertEdge(int v1,int v2)
  57.     {
  58.         edge* e=new edge(lv[v1-1],lv[v2-1]);
  59.         le.push_back(e);
  60.         lv[v1-1]->setEdge(e);
  61.         lv[v2-1]->setEdge(e);
  62.     }
  63.     int areAdjacent(int v1,int v2)
  64.     {
  65.         if(v1!=v2)
  66.         {
  67.             vector<edge*> v = lv[v1-1]->getE();
  68.             vector<edge*>::iterator i;
  69.             vertice** x;
  70.             for(i=v.begin();i<v.end();i++)
  71.             {
  72.                 x=(*i)->getV();
  73.                 if(x[0]==lv[v2-1]||x[1]==lv[v2-1])
  74.                     return 1;
  75.             }
  76.             return 0;
  77.         }
  78.         return 0;
  79.     }
  80. };
  81. int a[100]={0};
  82. void dfs(graph G,int v)
  83. {
  84.     cout<<v<<" ";
  85.     a[v-1]=1;
  86.     for(int i=1;i<=G.numV();i++)
  87.         if(G.areAdjacent(v,i))
  88.             if(!a[i-1])
  89.                 dfs(G,i);
  90. }
  91. void dfs(graph G)
  92. {
  93.     for(int i=1;i<=G.numV();i++)
  94.         if(!a[i-1])
  95.             dfs(G,i);
  96. }
  97. main()
  98. {
  99.     int V,E;
  100.     cout<<"Number of vertices ?";
  101.     cin>>V;
  102.     cout<<"Number of edges?";
  103.     cin>>E;
  104.     graph g(V,E);
  105.     cout<<"Next,enter like this format:vertex-vertex,meaning that there is an edge between them"<<endl;
  106.     int x,y;
  107.     for(int i=1;i<=E;i++)
  108.     {
  109.         cin>>x>>y;
  110.         g.insertEdge(x,y);
  111.     }
  112.     dfs(g);
  113. }
  114.  
I run it and receive the "send the error report to ms" . About the idea, I think that it's right , so the error may be about pointer . Please help me
Jul 31 '07 #1
1 3923
JosAH
11,448 Expert 8TB
'printf' and/or 'cout' are your friends here. Sprinkle them into your code liberally
and try to narrow down where your bug is hiding. You don't need sophisticated
debuggers for this nasty little fellow. And don't be afraid of what MS Windows
has to say, it screams already about rebooting when you just move your bloody
mouse; ignore it.

kind regards,

Jos
Jul 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Lilith | last post by:
Is there a python module somewhere (been searching today, no luck) which has efficiently coded various graph-handling routines, such as finding the shortest path through a graph, or the set of all...
25
by: Magnus Lie Hetland | last post by:
Is there any interest in a (hypothetical) standard graph API (with 'graph' meaning a network, consisting of nodes and edges)? Yes, we have the standard ways of implementing graphs through (e.g.)...
1
by: entropy123 | last post by:
Hey all, In an effort to solve a sticky - for me - problem I've picked up Sedgewick's 'Algorithm's in C'. I've tried working through the first few problems but am a little stumped when he refers...
2
by: MLH | last post by:
A97 Am having difficulty displaying graph in Form View that I see fine in graph control on form opened in design view. I know I'm doing something wrong. If I open the form in design view - I...
0
by: mylog | last post by:
I have downloaded a GLEE(Graph Layout Execution Engine) and written the following code to display a windows form from a web page but i am encountering with a small problem on displaying the graph...
2
by: sriniwas | last post by:
Hi Frnd's, m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my...
4
by: Man4ish | last post by:
namespace ve/////////////////ve.h { struct VertexProperties { std::size_t index; boost::default_color_type color; }; }...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
1
by: Man4ish | last post by:
I am creating a graph using boost library, I am making the network using create_Network function() i am adding the vertices to this graph by creating the object g of class Graph. I am trying to...
0
by: eureka2050 | last post by:
Hi all, I am creating a radar chart containing 2 plots using jpgraph. My code is as follows:- include ("./jpgraph/src/jpgraph.php"); include ("./jpgraph/src/jpgraph_radar.php"); //...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.