Phần hình ảnh là bài tập của em về graph yêu cầu viết bằng adjacency list graph
hiện tại em ko biết làm phần count_edge, count_edge(int n), bool has_edge(int a,int b), vector<int>, bfs(int n ) và bool is_connected(int a,int b). Có anh chị nào cho em xin ý kiến để viết tiếp đc không ạ ?
#include<iostream>
#include<list>
using namespace std;
struct node{
int value;
node* next;
};
class graph{
private:
int n;
vector<node> *adj;
public:
graph(int n);
void add_edge(int a, int b);
bool has_edge(int a, int b);
int count_node();
int count_edge();
int count_edges(int n);
vector<int> bfs(int n);
bool is_connected(int a, int b);
};
graph:graph(int n){
adj= new vector<node>[n];
}
void graph::add_edge(int a, int b){
node tmp;
tmp.value=b;
tmp.next=nullptr;
adj[a].push_back(tmp);
}
int graph::count_node(){
return n;
}
Bạn có thể mô tả bằng lời (hơn là bằng code) cấu trúc dữ liệu của graph được không?
-...- -.- .. .-.. .-.. - .... . -... . .- ... - .-.-.