Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <list>
- #include <queue>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #define N 13
- #define q 3
- using namespace std;
- int fdisp(int x) {
- return (q - x % q) % N;
- }
- bool cautare(list <int> H[], int x) {
- int cheie = fdisp(x);
- auto rezultat = find(H[cheie].begin(), H[cheie].end(), x);
- if (rezultat != H[cheie].end())
- return true;
- return false;
- }
- void inserare(list <int> H[], int x) {
- if (cautare(H, x)) {
- cout << "Valoarea exista in tabel.\n";
- return;
- }
- int cheie = fdisp(x);
- H[cheie].push_back(x);
- }
- void eliminare(list <int> H[], int x) {
- if (!cautare(H, x)) {
- cout << "Valoarea nu exista in tabel.\n";
- return;
- }
- int cheie = fdisp(x);
- H[cheie].remove(x);
- }
- void afisaretab(list <int> H[]) {
- for (int i = 0; i < N; i++) {
- cout << "H[" << i << "] = ";
- for (int x : H[i]) {
- cout << x << " ";
- }
- cout << endl;
- }
- cout << "\n\n";
- }
- void citireMat(int A[10][10], int& n, int& m) {
- ifstream inp("D:\\graf.txt");
- int x, y;
- inp >> n >> m;
- for (int i = 1; i <= m; i++) {
- inp >> x >> y;
- A[x][y] = 1;
- A[y][x] = 1;
- }
- }
- void afisMat(int A[10][10], int& n) {
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- cout << A[i][j] << " ";
- }
- cout << endl;
- }
- }
- void citListaAd(list <int> LA[10], int& n, int& m) {
- ifstream inp("D:\\graf.txt");
- int x, y;
- inp >> n >> m;
- for (int i = 1; i <= m; i++) {
- inp >> x >> y;
- LA[x].push_back(y);
- LA[y].push_back(x);
- for (int i = 1; i < n; i++) {
- LA[i].sort();
- }
- }
- }
- void afisListaAd(list <int> lista) {
- for (list <int> ::iterator it = lista.begin(); it != lista.end(); it++) {
- cout << *it << " ";
- }
- cout << endl;
- }
- void grafuriMatrice() {
- // matrice adiacenta:
- ifstream inp("D:\\graf.txt");
- int A[10][10];
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++)
- A[i][j] = 0;
- }
- int x, y;
- x = y = 10;
- citireMat(A, x, y);
- afisMat(A, y);
- }
- void grafuriListe() {
- int n = 5, m = 5;
- list <int> listaAd[10];
- citListaAd(listaAd, n,m);
- for (int i = 1; i <= n; i++) {
- cout << i << ": ";
- afisListaAd(listaAd[i]);
- }
- }
- int main() {
- grafuriListe();
- }
Advertisement
Add Comment
Please, Sign In to add comment