Untitled
unknown
c_cpp
10 months ago
1.4 kB
7
Indexable
/*
Scrivere un sottoprogramma che riceve in ingresso le teste di due liste dinamiche di interi, dette l1 e l2. Il
sottoprogramma verifica se le due liste contengono esattamente lo stesso insieme di valori, indipendentemente da
eventuali ripetizioni di ciascun elemento. In caso positivo il sottoprogramma restituisce 1 altrimenti 0.
Esempio 1:
Se il sottoprogramma riceve
l1: 1 -> 2 -> 3 -> 1
l2: 2 -> 2 -> 1 -> 3
allora restituisce 1.
Esempio 2:
Se il sottoprogramma riceve
l1: 1 -> 2 -> 3 -> 1
l2: 1 -> 4 -> 3
allora restituisce 0.
Esempio 3:
Se il sottoprogramma riceve
l1: 1 -> 2 -> 3 -> 1
l2: 1 -> 2 -> 1
allora restituisce 0.
*/
#include <stdio.h>
int presente(nodo_t *lista, int num)
{
nodo_t *curr = lista;
while(curr != NULL)
{
if(curr->num == num)
{
return 1;
}
curr = curr -> next;
}
return 0;
}
int confrontaLista(nodo_t *l1, nodo_t *l2)
{
nodo_t *curr1 = l1;
nodo_t *curr2 = l2;
while(curr1 != NULL)
{
if(!presente(l2, curr1->num))
{
return 0;
}
curr1 = curr1->next;
}
while(curr2 != NULL)
{
if(!presente(l1, curr2->num))
{
return 0;
}
curr2 = curr2->next;
}
return 1;
}
int main() {
// Write C code here
printf("Try programiz.pro");
return 0;
}Editor is loading...
Leave a Comment