1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: fix typos (#18229)

This commit is contained in:
Turiiya
2023-05-25 15:54:46 +02:00
committed by GitHub
parent caee3935a5
commit 993546a0a2
28 changed files with 89 additions and 89 deletions

View File

@ -22,7 +22,7 @@ $ ./an_executable.EXE
Code based from : Data Structures and Algorithms Made Easy: Data Structures and Algorithmic Puzzles, Fifth Edition (English Edition)
pseudo code written in C
This idea is quite different: it uses a priority queue to store the current
shortest path evaluted
shortest path evaluated
The priority queue structure built using a list to simulate
the queue. A heap is not used in this case.
*/
@ -38,17 +38,17 @@ mut:
// The "push" always sorted in pq
fn push_pq[T](mut prior_queue []T, data int, priority int) {
mut temp := []T{}
lenght_pq := prior_queue.len
pq_len := prior_queue.len
mut i := 0
for i < lenght_pq && priority > prior_queue[i].priority {
for i < pq_len && priority > prior_queue[i].priority {
temp << prior_queue[i]
i++
}
// INSERTING SORTED in the queue
temp << NODE{data, priority} // do the copy in the right place
// copy the another part (tail) of original prior_queue
for i < lenght_pq {
for i < pq_len {
temp << prior_queue[i]
i++
}
@ -59,16 +59,16 @@ fn push_pq[T](mut prior_queue []T, data int, priority int) {
// Change the priority of a value/node ... exist a value, change its priority
fn updating_priority[T](mut prior_queue []T, search_data int, new_priority int) {
mut i := 0
mut lenght_pq := prior_queue.len
mut pq_len := prior_queue.len
for i < lenght_pq {
for i < pq_len {
if search_data == prior_queue[i].data {
prior_queue[i] = NODE{search_data, new_priority} // do the copy in the right place
prior_queue[i] = NODE{search_data, new_priority} // do the copy in the right place
break
}
i++
// all the list was examined
if i >= lenght_pq {
if i >= pq_len {
print('\n This data ${search_data} does exist ... PRIORITY QUEUE problem\n')
exit(1) // panic(s string)
}
@ -126,7 +126,7 @@ fn dijkstra(g [][]int, s int) {
mut n := g.len
mut dist := []int{len: n, init: -1} // dist with -1 instead of INIFINITY
mut path := []int{len: n, init: -1} // previous node of each shortest paht
mut path := []int{len: n, init: -1} // previous node of each shortest path
// Distance of source vertex from itself is always 0
dist[s] = 0
@ -223,13 +223,13 @@ fn main() {
[5, 15, 4, 0],
]
// To find number of coluns
// To find number of columns
// mut cols := an_array[0].len
mut graph := [][]int{} // the graph: adjacency matrix
// for index, g_value in [graph_01, graph_02, graph_03] {
for index, g_value in [graph_01, graph_02, graph_03] {
graph = g_value.clone() // graphs_sample[g].clone() // choice your SAMPLE
// allways starting by node 0
// always starting by node 0
start_node := 0
println('\n\n Graph ${index + 1} using Dijkstra algorithm (source node: ${start_node})')
dijkstra(graph, start_node)