Dfs Sis 457.docx

  • Uploaded by: Aldo Lopez
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Dfs Sis 457.docx as PDF for free.

More details

  • Words: 223
  • Pages: 3
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace DFS { public class Grafo { public Grafo() { Vertices = new List>(); } public List> Vertices { get; set; } } }

using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace DFS { public class Vertice { public Vertice() { Vecinos = new List>(); } public Vertice(T inicial) : this() { Value = inicial; } public T Value { get; set; } public bool Visitado { get; set; } public List> Vecinos { get; set; } } }

using using using using

System; System.Collections; System.Collections.Generic; System.Linq;

using System.Text; using System.Threading.Tasks; namespace DFS { class Program { static Stack _pila = new Stack(); static Grafo<string> _grafo = new Grafo<string>(); static void DFS(Vertice<string> v) { var found = _grafo.Vertices.FirstOrDefault(ver => ver.Value == v.Value); if (found != null && found.Visitado == false) { found.Visitado = true; Console.WriteLine(found.Value); // Tarea: Usar la pila en la logica _pila.Push(found); foreach (var vecino in found.Vecinos) { DFS(vecino); } } } static void Main(string[] args) { Console.WriteLine("Primer Ejemplo"); var v1 = new Vertice<string>(); v1.Value = "2"; var v2 = new Vertice<string>(); v2.Value = "0"; var v3 = new Vertice<string>(); v3.Value = "1"; var v4 = new Vertice<string>(); v4.Value = "3"; v1.Vecinos.Add(v2); v2.Vecinos.Add(v1); v3.Vecinos.Add(v1); v1.Vecinos.Add(v3); v3.Vecinos.Add(v2); v2.Vecinos.Add(v3); v1.Vecinos.Add(v4); v4.Vecinos.Add(v1); _grafo.Vertices.Add(v1); _grafo.Vertices.Add(v2); _grafo.Vertices.Add(v3);

_grafo.Vertices.Add(v4); DFS(v1); Console.ReadLine(); } } }

Related Documents

Dfs Sis 457.docx
April 2020 7
Dfs
November 2019 10
Dfs
November 2019 9
Dfs
June 2020 4
Dfs
November 2019 8
Dfs
April 2020 7

More Documents from ""