Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Macierz Incydencji.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- #include <stack>
- using namespace std;
- int w, k, i, j, v1, v2;
- int wierzcholki = 10000;
- double **tab = new double *[w];
- bool *visited = new bool[w];
- int ile_krawedzi = 0;
- void macierzIncyd()
- {
- string linia;
- fstream plik;
- plik.open("C:\\Users\\Agata\\Desktop\\grafy.txt", ios::in);
- if (plik.good() == true)
- {
- while (!plik.eof())
- {
- while ((getline(plik, linia)))
- {
- ile_krawedzi++;
- }
- plik.close();
- cout << "Plik wczytany!" << endl;
- }
- cout << "Ilosc krawedzi: " << ile_krawedzi << endl;
- //alokacja pamieci DO TABLICY 2D i jej zerowanie
- for (int i = 0; i < 7; ++i)
- {
- tab[i] = new double[ile_krawedzi]; //alokacja pamieci
- for (int j = 0; j < ile_krawedzi; ++j) //wpisanie wartosci do tablicy
- tab[i][j] = 0;
- }
- // WYSWIETLANIE TABLICY O MALYCH WARTOSCIACH
- // cout << " ";
- // for(int f = 0; f < ile_krawedzi; f++) cout << setw(3) << i;
- // cout << endl << endl;
- // for(int f = 0; f < 10000; f++)
- // {
- // cout << setw(3) << i;
- // for(j = 0; j < ile_krawedzi; j++) cout << setw(3) << (int) tab[i][j];
- // cout << endl;
- // }
- plik.open("C:\\Users\\Agata\\Desktop\\grafy.txt", ios::in);
- if (plik.good() == true)
- {
- while (!plik.eof())
- {
- int found;
- string halp;
- int i = 0;
- while ((getline(plik, linia)))
- {
- found = linia.find(" ");
- halp.insert(0, linia, 0, found); //indeks kto
- v1 = atoi(halp.c_str());
- halp.clear();
- halp.insert(0, linia, found + 1, 6);
- v2 = atoi(halp.c_str());
- tab[v1][i] = 1;
- tab[v2][i] = 1;
- cout << v1 << " " << v2 << endl;
- halp.clear();
- i++;
- }
- plik.close();
- cout << "Plik wczytany!" << endl;
- }
- /* cout << endl << "Macierz INCYDENCJI po wypelnieniu" << endl << endl;
- cout << " ";
- for(i = 0; i < ile_krawedzi; i++) cout << setw(3) << i;
- cout << endl << endl;
- for(i = 0; i < 7; i++)
- {
- cout << setw(3) << i;
- for(j = 0; j < ile_krawedzi; j++) cout << setw(3) << (int) tab[i][j];
- cout << endl;
- }*/
- }
- }
- }
- void DFSincyd(int v)
- {
- visited[v] = true; // Zaznaczamy wierzchołek jako odwiedzony
- cout << v << " "; // Wypisujemy numer odwiedzonego wierzchołka
- for (int i = ile_krawedzi - 1; i >= 0; i--)
- if (tab[v][i]) // Jeśli v należy do i-tej krawędzi,
- for (int j = 0; j < 7; j++) // to szukamy jej drugiego końca
- if (j != v && tab[j][i])
- {
- if (!visited[j]) DFSincyd(j); // Jeśli nie odwiedzony, idziemy do niego
- break;
- }
- }
- int main()
- {
- macierzIncyd();
- DFSincyd(1);
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement