C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 11th, 2012, 03:47 PM
deerpark deerpark is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 deerpark User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 54 sec
Reputation Power: 0
Graph Implementation in c++

I have a a vector<vector<string>> which holds the value if Nodes and edges.
i.e
1,2,1 // here 1 is starting node, 2 is ending node and 1 is weight
1,3,4
....
Code:
vector<vector<string>> inputdata;
total_node =4;

So far I created a 3 class, Node class, Edge Class and Graph class
Code:
class Node {
public:
		Node(string NodeId,string NodeName)
		{
			_nodeId = NodeId;
		}

		string GetNodeId()
		{
			return _nodeId;
		}

		void addAdjacentNode(Node *startNode, Node *dstNode, int cost)
		{
			Edge edge(startNode,dstNode,cost);
			_neighborEdge.push_back(edge);
		}

	private: 
		string _nodeId;
		vector <Edge> _neighborEdge;
	}


class Edge {

public:
	Edge(Node *startNode, Node *endNode, int weight)
	{
		originatingNodeId = startNode;
		destinationNodeId = endNode;
		cost = weight;
	}

private:
	Node *originatingNodeId;
	Node *destinationNodeId;
	int cost;
}

class Graph {
public:

	void addNode(Node *node)
	{
		graph.push_back(node);
	}

private:
	vector<Node*> graph;
}

I am not sure, how should I make use of the class in the main program to create a graph .
How should I be calling my graph class to create a graph. Do I need to add any methods to any of my class to make it work.

Appreciate your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Graph Implementation in c++

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap