Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct wierzcholek
- {
- int nr;
- wierzcholek *nast;
- };
- class graf
- {
- int n;
- wierzcholek *tab[100];
- public:
- graf();
- int LiczbaWierzcholkow();
- int LiczbaKrawedzi();
- int MaxStopien();
- int MinStopien();
- int getN();
- void dodajPol(int wierzA, int wierzB);
- friend istream &operator>>(istream& we, graf& G);
- friend ostream& operator<<(ostream& wy, const graf& G);
- };
- graf::graf()
- {
- n=0;
- for(int u=0; u<100; u++)
- {
- tab[u]=NULL;
- }
- }
- int graf::getN(){
- return n;
- }
- void graf::dodajPol(int wierzA, int wierzB){
- wierzcholek* pom, *pom2;
- pom = tab[wierzA];
- pom2 = new wierzcholek;
- pom2->nr = wierzB;
- while(pom->nast != NULL) pom = pom->nast;
- pom->nast = pom2;
- pom = tab[wierzB];
- pom2 = new wierzcholek;
- pom2->nr = wierzA;
- while(pom->nast != NULL) pom = pom->nast;
- pom->nast = pom2;
- }
- ostream& operator<<(ostream &wy, const graf& G)
- {
- wierzcholek *pom;
- for(int u=0;u<G.n;u++)
- {
- pom = G.tab[u]->nast;
- wy<<u<<": ";
- while(pom != NULL){
- wy<<pom->nr<<" ";
- pom = pom->nast;
- }
- wy<<endl;
- }
- return wy;
- }
- istream& operator>>(istream& we, graf& G)
- {
- we>>G.n;
- wierzcholek* pom;
- for(int i=0 ; i<G.n ; i++){
- pom = new wierzcholek;
- pom->nr = i;
- G.tab[i] = pom;
- }
- return we;
- }
- int main(){
- graf G;
- cin>>G;
- G.dodajPol(1, 2);
- cout<<G;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement