Mustaqil ishi Urganch-2023 reja


Masalaning quyilishi: berilgan


Download 19.04 Kb.
bet3/3
Sana08.05.2023
Hajmi19.04 Kb.
#1446205
1   2   3
Bog'liq
Kommivoyadjer haqida masala

Masalaning quyilishi: berilgan n = 4, e = 6 2 -> 0, 0 -> 2, 1 -> 2, 0 -> 1, 3 -> 3, 1 -> 3 grafning 2 uchidan boshlab chuqurligini aniqlash;

  • Masalaning quyilishi: berilgan n = 4, e = 6 2 -> 0, 0 -> 2, 1 -> 2, 0 -> 1, 3 -> 3, 1 -> 3 grafning 2 uchidan boshlab chuqurligini aniqlash;

  • Dastur kodi:#include

  • using namespace std;

  • class Graph

  • {

  • int V; list *adj;

  • void DFSUtil(int v, bool visited[]);

  • public:

  • Graph(int V); // Constructor

  • // function to add an edge to graph

  • void addEdge(int v, int w);

  • void DFS(int v);

  • };

  • Graph::Graph(int V){ this->V = V;

  • adj = new list[V];

  • } void Graph::addEdge(int v, int w){ adj[v].push_back(w);} void Graph::DFSUtil(int v, bool visited[]){ visited[v] = true;cout << v << " ";

  • list::iterator i;

  • for (i = adj[v].begin(); i != adj[v].end(); ++i)

  • if (!visited[*i])

  • DFSUtil(*i, visited);

  • }

void Graph::DFS(int v)

  • void Graph::DFS(int v)

  • {

  • bool *visited = new bool[V];

  • for (int i = 0; i < V; i++)

  • visited[i] = false;

  • DFSUtil(v, visited);

  • }

  • int main(){

  • Graph g(4);g.addEdge(0, 1);

  • g.addEdge(0, 2);

  • g.addEdge(1, 2);

  • g.addEdge(2, 0);

  • g.addEdge(2, 3);

  • g.addEdge(3, 3);

  • cout << "gragning chuqurliga"

  • " (2 dan boshlab) \n";

  • g.DFS(2);

  • return 0; }

http://fayllar.org



Foydalanilgan adabiyotlar:

1. "Algoritmikalar" avtori: Sedgewick, Robert


2. "Algoritm tuzilishlari" avtori: Levitin, Anany
3. "Algoritmalar: texnologik kuzatuv usullari" avtori: Knuth, Donald
4. "Algoritmikalar va Strukturli Ma’lumotlar" avtori: Sahni, Sartaj
5. "Algoritmalar. Masalalar. Java tillari" avtori: Goodrich, Michael T.
6. "Algoritmlar va ma’lumotlar strukturasi" avtori: Cormen, Thomas H.
7. "Ma’lumotlar strukturasi va algoritmalar" avtori: Weiss, Mark Allen
8. "Kutilmagan nazorat: ma’lumotlar, algoritmalar va internet zamonaviylik" avtori: Greenlaw, Raymond
9. "Algoritmikalar: Java dasturlash tillari" avtori: Sedgewick, Robert
10. "Algoritmalar va algoritmlash tillari" avtori: Brassard, Gilles va Bratley, Paul.
11. Internetdagi manbalar
Download 19.04 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling