Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatgupta310198 committed Sep 14, 2020
1 parent 8d9adf1 commit fa1f46e
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 32 deletions.
23 changes: 21 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

// import formatted I/O package
import (
"algos/src/Algo/other/permutaions"
"algos/src/Algo/search/graph"
"algos/src/Other/permutaions"
"algos/src/graph"
"fmt"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions src/graph/dfs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package graph

import (
"fmt"
)

// Dfs performs Depth Fist Search
func (g *Graph) Dfs(vertex *Vertex) {
//visited := []bool{false, false}

visited := make(map[string]bool)
for i := range g.Vertices {
visited[g.Vertices[i].Label] = false
}
g.dfsUtil(vertex, visited)

}

// dfsUtil is utility for Dfs
func (g *Graph) dfsUtil(vertex *Vertex, visited map[string]bool) {

visited[vertex.Label] = true
fmt.Printf("\n%s ", vertex.Label)
for _, v := range vertex.AdjList {
if visited[v.Label] == false {
g.dfsUtil(v, visited)
}
}

}
27 changes: 1 addition & 26 deletions src/Algo/search/graph/graph.go → src/graph/graph.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graph


import (
"fmt"
)
Expand Down Expand Up @@ -35,32 +36,6 @@ func (g *Graph) AddEdge(srcVertex, dstVertex *Vertex) *Vertex {
srcVertex.AdjList = append(srcVertex.AdjList, dstVertex)
return srcVertex
}

// Dfs performs Depth Fist Search
func (g *Graph) Dfs(vertex *Vertex) {
//visited := []bool{false, false}

visited := make(map[string]bool)
for i := range g.Vertices {
visited[g.Vertices[i].Label] = false
}
g.dfsUtil(vertex, visited)

}

// dfsUtil is utility for Dfs
func (g *Graph) dfsUtil(vertex *Vertex, visited map[string]bool) {

visited[vertex.Label] = true
fmt.Printf("\n%s ", vertex.Label)
for _, v := range vertex.AdjList {
if visited[v.Label] == false {
g.dfsUtil(v, visited)
}
}

}

// PrintGraph prints the create graph G
func (g *Graph) PrintGraph() {
fmt.Printf("Number of vertices %d\n", g.VertexCount)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/DS/tree/main.go → src/tree/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"../tree/bst"
bst2 "algos/src/tree/bst"
"fmt"
)

func main() {
b := new(bst.T)
b := new(bst2.T)
//b.Insert(1)
a := [] int {1, 2, 3, 7, 4, 5, 9, 6, 12, 15}
for i :=range a {
Expand Down

0 comments on commit fa1f46e

Please sign in to comment.