Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
prog-2-lab-assigments
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
20041679 .
prog-2-lab-assigments
Commits
08093476
Commit
08093476
authored
1 year ago
by
20041679
Browse files
Options
Downloads
Patches
Plain Diff
added Compito 27 luglio
parent
89ebc350
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Turno 3/1.c
+44
-0
44 additions, 0 deletions
Turno 3/1.c
Turno 3/2.c
+23
-0
23 additions, 0 deletions
Turno 3/2.c
with
67 additions
and
0 deletions
Turno 3/1.c
0 → 100644
+
44
−
0
View file @
08093476
// Dalla consegna non si capisce niente, a partire dal fatto che
// si richiede n < m e nell'esempio n è 2 e m è 5.
// Inoltre cosa bisogna fare se i nodi non esistono tutti?
// E da che numero partono le posizioni?
// Gli estremi sono inclusi o esclusi?
//
// Questa implementazione richiede n <= m (si può eliminare
// anche un singolo elemento) e elimina i nodi se e solo se
// esistono tutti, le posizioni partono da 0 e gli estremi
// sono inclusi
void
f
(
Link
*
list
,
size_t
n
,
size_t
m
)
{
size_t
pos
=
0
;
// skip the first `n` nodes
while
(
*
list
&&
pos
<
n
)
{
list
=
&
(
*
list
)
->
next
;
++
pos
;
}
if
(
*
list
)
{
Link
skip
=
*
list
;
pos
=
0
;
// traverse every node of the deletion area.
while
(
skip
&&
pos
<
m
-
n
)
{
skip
=
skip
->
next
;
++
pos
;
}
if
(
skip
)
{
// every node that needs to be deleted exists,
// proceed with deletion
skip
=
*
list
;
pos
=
0
;
while
(
skip
&&
pos
<
m
-
n
)
{
Link
next
=
skip
->
next
;
free
(
skip
);
skip
=
next
;
++
pos
}
// skip->next can be assumed to exist since this is the
// true branch of `if (skip)`;
// link the last node of the skipped area with the first
// node after the deleted area
*
list
=
skip
->
next
;
}
}
}
This diff is collapsed.
Click to expand it.
Turno 3/2.c
0 → 100644
+
23
−
0
View file @
08093476
// first call: sum1 = 0, sum2 = 0
int
f
(
Link
list1
,
Link
list2
,
int
sum1
,
int
sum2
)
{
if
(
list1
&&
list2
)
{
sum1
+=
list1
->
data
;
sum2
+=
list2
->
data
;
list1
=
list1
->
next
;
list2
=
list2
->
next
;
}
else
if
(
list1
)
{
sum1
+=
list1
->
data
;
list1
=
list1
->
next
;
}
else
if
(
list2
)
{
sum2
+=
list2
->
data
;
list2
=
list2
->
next
;
}
else
{
return
sum1
>
sum2
?
sum1
:
sum2
;
}
return
f
(
list1
,
list2
,
sum1
,
sum2
);
}
// Complessità in tempo: O(max(|list1|, |list2|))
// Complessità in spazio: O(max(|list1|, |list2|))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment