| | |
Directed graph
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
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
C++ Syntax (Toggle Plain Text)
// 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 10:48 pm. Reason: add code tags
![]() |
Similar Threads
- How to detect circle in a directed graph? (Java)
- Finding path in a graph using linked list (C)
- Directed Graph Problem (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: LPTSTR
- Next Thread: Mind-blowing problem here (At least for me)
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





