Need to know how to write C++ code to draw a graph with adjacnecy list


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Need to know how to write C++ code to draw a graph with adjacnecy list

  1. #1
    Join Date
    Sep 2006
    Posts
    17

    Post Need to know how to write C++ code to draw a graph with adjacnecy list

    Hi all;
    I want to write a program for my own practice . In this program, I Need to know how to write C++ code to draw a graph with adjacnecy list. For thsi I prepared an input file with data in array type and also wrote the code to read input files. Now I need help to write C++ code to draw a graph with adjacnecy list Here is the more details of my problem.

    My Input: A directed graph G represented by a set of vertices and a set of edges.
    My Output should : Two parts. The first part is the same graph G represented by adjacency lists. The second part is the transpose GT represented by adjacency lists
    thanks

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    Hi,
    are you talking about a graphical representation of your graph? Painting on your screen depends entirely on the O/S and compiler you use. We need more info to help you there...
    Cheers,
    D
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    I think that linked lists of the vertices and edges are more direct to deal with rather than arrays. You are going to have variable number of edges which are adjacent to a vertex.

    Create a vertex struct and an edge struct. This is the place to store a name or other identifier of the graph vertex, other information about that vertex, the distance or weight of the edge, and links/pointers to the next struct in the list.

    Your Vertex structs in your vertices list will have links to the next vertex in the vertices list and a link to the first edge in the edge list. Add edge structs as you encounter them. If this is a undirected graph you need to make two entries for each edge.

    Your approach to the transposed graph should be self evident when you have your other structure. (copy the vertice list, reverse the direction of the edge and redistribute the edges in the edge lists)

    There are LOTS of resources online or in your local (college/university) library which might help you with the code for this project. Google "C++ adjacency list" and you should find some help with the actual code (this is a nice programming project for college data structures classes ...)
    Last edited by nspils; 09-18-2006 at 10:19 AM.

  4. #4
    Join Date
    Sep 2006
    Posts
    17
    TO Dkyb: yes, I am talking about a graphical representation of graph. Please provide any c++ codes if you have it and I want to try plug them in my codes and test it.
    Thanks for your time and input.

    TO nspils:
    Thanks for the details answer, is anyway I can use array type input data and able to draw the graph? If possible then can you provide some samples of C++ code to draw the graph, please?

  5. #5
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    My response was addressed to the "data structure" for addressing/manipulating the graph, not its presentation to the screen (drawing it). My mistake - I misread what you were asking.

  6. #6
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    Hi,
    I can only tell you 'bout VS:
    Everytime you draw on a device (eg screen, printer, plotter,...) you net to attain a pointer to the devices "device context" and use the methods in the DC to do the painting.
    Code:
    // use this code in the OnDraw - event - handler in your View-class or Dialog - class
    CDC* pDC = GetDC();
    pDC->MoveTo(x1,y1);
    pDC->DrawTo(x2,y2);
    pDC->SetPixel(x3,y3,RGB(127,255,12));
    pDC->Rectangle(x1,y1,x2,y2);
    ...
    You'll have to read up in the MSDN on the exact syntax (and pitfalls), but in general that's it.

    Cheers,
    D
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  7. #7
    Join Date
    Sep 2006
    Posts
    17
    Hi all;
    thanks for the valuable input. Let me try and if i need more help I will reply you.

    thanks
    shailesh33

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2005, 12:40 PM
  2. VS.Net and Code Behind
    By Chaitanya Marvici in forum ASP.NET
    Replies: 6
    Last Post: 07-21-2003, 10:15 AM
  3. Replies: 0
    Last Post: 05-20-2002, 10:39 PM
  4. Replies: 0
    Last Post: 04-03-2001, 05:32 PM
  5. Write HTML code to email
    By Larry in forum ASP.NET
    Replies: 0
    Last Post: 06-29-2000, 05:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center