Data structures graphs
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Data structures graphs

  1. #1
    Join Date
    Jan 2010
    Posts
    161

    Data structures graphs

    Hello everyone, I am trying to work with graphs and trying to put weight on edges between one node to another.
    The problem is, I don't know whether is the syntax or the procedure but it does not work.

    This is my graphnode class

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Graphs
    {
      public class GraphNode<T>
      {
        private T id;
        private T distance;
        private LinkedList<T> adjList;
    
        public GraphNode(T id)
        {
          this.id = id;
          adjList = new LinkedList<T>();
         
        }
    
        public void AddEdge(GraphNode<T> to)
        {
          adjList.AddLast(to.ID);
        }
        public T ID
        {
          set { this.id = value; }
          get { return this.id; }
        }
        public LinkedList<T> GetAdjList()
        {
          return adjList;
        }
    
        public T cost
        {
          set { cost = value; }
          get { return cost; }
    
        }
      }
    }
    You can see th function public T cost that's the one I am using to add weight to edges from one node to another

    here is a code which sends the cost in order to add it

    Code:
     public void AddEdge(T from, T to,T distance)
        {
          foreach (GraphNode<T> n in nodes)
          {
            if (from.Equals(n.ID))
            {
              n.GetAdjList().AddLast(to);
              n.cost = distance;    
            }
          }
    
        }
    I send to this method the two nodes which I want to add the weight to, then once the two nodes are present and validated it does add the cost to it from the value in distance..
    during the breakpoint when i get to n.cost = distance; it crashes and does not even through an erros, it just say the debugger stopped.

  2. #2
    Join Date
    Jan 2010
    Posts
    161

    Re: Data structures graphs

    please some help

  3. #3
    Join Date
    Oct 2004
    Location
    Rocket City
    Posts
    219

    Re: Data structures graphs

    The <T> in the examples is just that - an example. You are supposed to insert system types such as <System.String>, <System.Int32> or your own named types such as <GraphNodeClass>.

  4. #4
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Data structures graphs

    Where do you create your GraphNode<T> object? As the previous poster indicated, you need to decide what Type your "T" is. For example:
    Code:
    GraphNode<string> myGraphNode = new GraphNode<string>();
    Then the compiler will generate code for the GraphNode class. In effect, replacing all of the T's with "string".
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center