Search
 
SCRIPT & CODE EXAMPLE
 

CPP

grpah class data structure


#include <bits/stdc++.h>
using namespace std;

class Graph {
	int V;
	list<int> *l;

public:
	Graph(int v){
		V = v;
		l = new list<int>[V];
	}

	void addEdge(int u, int v, bool bidir = true){
		l[u].push_back(v);
		if(bidir){
			l[v].push_back(u);
		}
	}

	void printEdge(){
		for(int i=1;i<V;i++){
			cout<<i<<"-->";
			for(auto node: l[i]){
				cout<<node<<" ";
			}
			cout<<endl;
		}
	}

};


int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	Graph g(5);
	g.addEdge(1, 2);
	g.addEdge(2, 3);
	g.addEdge(3, 4);
	g.addEdge(1, 3);

	g.printEdge();	

	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: file descriptor linux c++ 
Cpp :: what is difference between single inverted and double inverted in programming languages 
Cpp :: unreal get eobjecttypequery cpp´ 
Cpp :: ue log c++ unreal 
Cpp :: strcat without using built in function 
Cpp :: gmod hitman job code 
Cpp :: insert at position in vector c++ 
Cpp :: create and write to a file c++19 
Cpp :: c++ while loop decrement 
Cpp :: eosio get time 
Cpp :: count function vector c++ 
Cpp :: c++ throw exception 
Cpp :: c++ find index of an element 
Cpp :: c++ display numbers as binary 
Cpp :: how to get the player view point location and rotation in ue4 c++ 
Cpp :: c ++ program to search hashmap 
Cpp :: qlabel font color 
Cpp :: go through std vector 
Cpp :: c++ vector element search 
Cpp :: helloworld in c++ 
Cpp :: c++ program to calculate discount 
Cpp :: how to convert character to lowercase c++ 
Cpp :: what is the difference between i++ and ++ i ? 
Cpp :: how to run a c++ file from terminal linux 
Cpp :: how to round a double to 2 decimal places in c++ 
Cpp :: c++ reverse integer 
Cpp :: c++ hide show console 
Cpp :: c++ return multiple values 
Cpp :: c++ console color 
Cpp :: remove last index of the string in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =