Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2002

    C++ and graphs / Vectors vs Arrays

    I need to implement some graph algorithms to solve a problem.
    The problem involve making minimum spanning tree and all-pair-shortest-path graph from a given graph.
    I never do graphs in C++ before so I have a few questions.

    Should I build my graph data structures (vertices, edges..) from scratch using struct or something else? or is there a premade library that I an use(Hopefully there is and someone guide me to where I can learn about it)? My C++ experience is quite limited and I am doing lots of research to do this at the moment.

    Also are vectors really superior over arrays? I found out that vectors can be expanded in size with much ease while arrays can not. Is there something else I am missing beside this advantage?

    Thanks a lot.

  2. #2
    Join Date
    Oct 2003
    Georgetown, Ontario
    Not sure about the graph library, but you should use vectors instead of arrays. There are no disadvantages to using vectors.
    ии Repeat after me... ProSupport is the best... Prosupport is... ии
    ProSupport Host Support System - OUT NOW! Grab a copy yourself and see what the hype is about!
    VertiHost Inc. - We run a quality business. Do you?

  3. #3
    Vectors are far superior to arrays. The main advantage is you don't have to initialise them with a preset size. It takes a while to get used to how to iterate over them. You should do a bit of searching for graphs in the STL. I found the following site which might be of use to you:


  4. #4
    boost has many add-on libraries for c++. Luckily for you, one of them is a Graph library. I can't paste a URL though because I don't have enough posts and there are some weird forum restrictions, so just google "c++ boost graph".

    As for array vs. vector... array's are contiguous blocks of memory. That's all really. There are several STL containers built around arrays, such as vectors and lists and strings. You probably shouldn't be using array's until you understand what you are doing better, so just stick with vectors for now.

    Or you could read up on the basics of data structures

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts