1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <iostream>
using namespace std;
class liste
{
public:
int n;
liste *next;
};
liste *L,*tete;
char rep;
void creation(liste *tete)
{
do
{
liste *L=new liste;
cout<<"Entrez un nombre\n";
cin>>L->n;
L->next=tete;
tete=L;
cout<<"Autre element?O/N\n";
cin>>rep;
}
while (rep=='o' || rep=='O');
}
void appartient(liste *tete)
{
int a;
cout<<"Donnez un nombre à rechercher\n";
cin>>a;
while (L!=NULL)
{
if (L->n==a) cout<<"appartient" ;
else cout<<"n'appartient pas";
L=L->next;
};
}
int main()
{
creation(tete);
appartient(L);
return 0;
} |
Partager