#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
struct nodo
{
int valore;
nodo *succ;
};
void inserisci(nodo *&testa,nodo *nuovo)
{
nodo *temp=NULL;
if(testa==NULL)
{
nuovo->succ=NULL;
testa=nuovo;
}
else
{
temp=testa;
testa=nuovo;
testa->succ=temp;
}
}
void visualizza(nodo *testa)
{
cout<<endl;
while(testa!=NULL)
{
cout<<" "<<testa->valore;
testa=testa->succ;
}
cout<<endl;
}
void elimina_valori_pari(nodo *&testa)
{
nodo *temp=NULL;
nodo *precedente=NULL;
temp=testa;
while(temp!=NULL)
{
if((temp->valore)%2==0 && temp==testa)
{
temp=testa;
testa=testa->succ;
delete temp;
}
else if((temp->valore)%2==0 && temp!=testa)
{
precedente->succ=temp->succ;
delete temp;
temp=precedente;
}
precedente=temp;
temp=temp->succ;
}
}
int main()
{
srand(time(0));
nodo *nuovo=NULL;
nodo *testa=NULL;
for(int i=0;i<235;i++)
{
nuovo=new nodo;
nuovo->valore=(rand()%221);
inserisci(testa,nuovo);
}
visualizza(testa);
elimina_valori_pari(testa);
visualizza(testa);
}
Post Views: 994