Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algoritmi-e-Strutture-Dati-2024-2025
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luca Ghirimoldi
Algoritmi-e-Strutture-Dati-2024-2025
Merge requests
!9
Lab6
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Lab6
lab6
into
main
Overview
0
Commits
2
Pipelines
0
Changes
4
Merged
Lab6
Luca Ghirimoldi
requested to merge
lab6
into
main
9 months ago
Overview
0
Commits
2
Pipelines
0
Changes
4
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
0a7e2af5
2 commits,
9 months ago
4 files
+
121670
−
1
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
lab6/ricerca.go
0 → 100644
+
78
−
0
View file @ 0a7e2af5
Edit in single-file editor
Open in Web IDE
package
main
import
(
"fmt"
_
"slices"
"strconv"
)
func
main
()
{
table
:=
[]
int
{
-
9
,
-
1
,
0
,
13
,
14
,
14
,
12
,
29
,
31
,
24
,
36
,
36
,
44
,
44
,
8
}
x1
,
x2
:=
algoX
(
table
,
14
)
y1
,
y2
:=
algoY
(
table
,
44
)
fmt
.
Println
(
x1
,
x2
,
y1
,
y2
)
}
func
algoX
(
table
[]
int
,
x
int
)
(
bool
,
string
)
{
s
:=
""
for
i
,
el
:=
range
table
{
if
el
==
x
{
s
+=
strconv
.
Itoa
(
i
)
}
}
if
s
!=
""
{
return
true
,
s
}
return
false
,
""
}
func
algoY
(
table
[]
int
,
x
int
)
(
bool
,
string
)
{
// slices.Sort(table)
// fmt.Println(table)
s
:=
""
low
,
high
:=
0
,
len
(
table
)
-
1
//LOW = 0, HIGH = 14
// MID = 7
//HIGH = 6
// MID = 0+6 = 3
// low = 4
for
low
<=
high
{
mid
:=
(
low
+
high
)
/
2
if
table
[
mid
]
<
x
{
low
=
mid
+
1
fmt
.
Println
(
low
,
mid
,
high
)
}
else
if
table
[
mid
]
>
x
{
high
=
mid
-
1
}
else
{
s
+=
strconv
.
Itoa
(
mid
)
table
[
mid
]
=
999
low
,
high
=
0
,
len
(
table
)
-
1
}
}
if
s
!=
""
{
return
true
,
s
}
return
false
,
""
}
//1) 0,1,2,3,4
//2) 4,3,6
//3)
/*
A X
B N
C X
D N
E N
F X
G Y
H N
4) no, algoX controlla tutte le posizione dell'array finche non trova l'elemento, Y è più efficente se è ordinato
5) AlgoX = ricercaIterative, AlgoY = ricerca binaria
6) bisogna aggiungere una variabile stringa dove contateno la posizione dell'elemento X, e ritorno la stringa
7) no, poichè effettuando la ricerca binaria, quando si trova un elemento si ferma,
per trovare i duplicati bisognerebbe implementare una ricerca che rimuove l'elemento trovato e riparte dall'inizio,
oppure che rimpiazza l'elemento trovato con un altro valore, cambia si la complessità
*/
\ No newline at end of file
Loading