Stanford Competetive Programming/06BGA(DFS).cpp
void TopologicalSort (int x) {
	if ((c == 'd') && (m <= n)) {
		DFS(x);
		cout << "Topological Sort gives:" << endl;
		for (int i = 0; i < n; i++) {
			cout << Stack.back() << "\t";
			Stack.pop_back();
		}
		cout << endl;
	} else {
		if (c != 'd') {
			cout << "Topological Sort cannot be performed as it is an undirected graph." << endl;
		} else {
			cout << "Topological Sort cannot be performed as the graph has cycles." << endl;
		}
	}
}
/* Topological sort can be performed in time Theta(V + E), since depth-first search takes Theta(V + E)
*  time and it takes O(1) time to insert each of the |V| vertices onto the front of the linked list.
*/
Topological sort can be performed in time Theta(V + E), since depth-first search takes Theta(V + E)
time and it takes O(1) time to insert each of the |V| vertices onto the front of the linked list.
Topological sort can be performed in time Theta ( V + E ) since depth - first search takes Theta ( V + E ) time and it takes O ( 1 ) time to insert each of the |V| vertices onto the front of the linked list .
void TopologicalSort (int x) {
	if ((c == 'd') && (m <= n)) {
		DFS(x);
		cout << "Topological Sort gives:" << endl;
		for (int i = 0; i < n; i++) {
			cout << Stack.back() << "\t";
			Stack.pop_back();
		}
		cout << endl;
	} else {
		if (c != 'd') {
			cout << "Topological Sort cannot be performed as it is an undirected graph." << endl;
		} else {
			cout << "Topological Sort cannot be performed as the graph has cycles." << endl;
		}
	}
}
void TopologicalSort ( int x ) { if ( ( c == ' ' ) && ( m <= n ) ) { DFS ( x ) ; cout << " " << endl ; for ( int i = 0 ; i < n ; i ++ ) { cout << Stack . back ( ) << " \t " ; Stack . pop_back ( ) ; } cout << endl ; } else { if ( c != ' ' ) { cout << " " << endl ; } else { cout << " " << endl ; } } }
Topological sort can be performed in time Theta(V + E), since depth-first search takes Theta(V + E)
time and it takes O(1) time to insert each of the |V| vertices onto the front of the linked list.
Topological sort can be performed in time Theta ( V + E ) since depth - first search takes Theta ( V + E ) time and it takes O ( 1 ) time to insert each of the |V| vertices onto the front of the linked list .