RSS Forums RSS

Directed graph

Please support our C++ advertiser: Programming Forums
Reply
Posts: 1
Reputation: steve2up is an unknown quantity at this point 
Solved Threads: 0
steve2up steve2up is offline Offline
Newbie Poster

Directed graph

  #1  
Dec 1st, 2008
Hi everyone, I am a U.student from China, I would like ask a question about my assignment.

For the directed graph, I would like to perform topological sort for sorting up nodes, but I encountered some problem in queue which is able to be removed or added with certain elements.

My question is how I can perform queue in topological sort function? my algorithm is here
// The topological sort
void DGraph::topologicalSort(){
	if(isTPSorted==false){
		int j=0;
		Queue ts;
		while(ts.size()!=0)
			/*dequeue()  dequeue for queue*/
		for(int i=0;i<50;i++){
			if (visitedTable[i]>=0 && inDegTable[i] == 0)
				/*enqueue(i)  enqueue for queue*/
		}
		while(ts.size()>0){                           
	                predTable[j]=dequeue();/*putting into predTable*/
			int a=predTable[j];
			j++;
			for(int k=0;k<50;k++){
				if(adjMatrix[a][k]==1){ 
					inDegTable[k]--;
					if (inDegTable[k] == 0){
				             /*enqueue(k) enqueue for queue*/
					}
				}
				
			}
		}
		isTPSorted = true;
	}
	return;
}

my professor gave a hint to perform queue:

In the implementation of the topological sort, a queue data structure is required. he said I can use the queue from the standard template library. Here are some short descriptions of the functions provided by the STL queue.

empty : true if the queue has no elements
front pop: returns a reference to the first
push : element of a queue removes the first element of a queue adds an element to the end of the queue

For example, include header <queue> and declare my queue as std::queue <int> Queue. And use push as Queue.push(int).

I could find some information in http://www.sgi.com/tech/stl/queue.html. but I don't catch up the point.

Thank you very much
Last edited by Ancient Dragon : Dec 1st, 2008 at 9:48 pm. Reason: add code tags
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 626 | Replies: 0 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:20 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC