Different type ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Different type ?

How can i solve this problem in c++ " invalid conversion list to int "

9th Feb 2021, 3:16 PM
Insaf Saidia
Insaf Saidia - avatar
7 Answers
+ 2
I mean that sounds pretty obvious. You can't simply convert a list into a number. But what exactly were you trying to do? Maybe you could share your code?
9th Feb 2021, 3:19 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 1
Share your code here. (Preferably made in code playground)
9th Feb 2021, 3:19 PM
Arsenic
Arsenic - avatar
+ 1
Insaf Saidia I think problem is here: liste plusoc(liste l) { int maxoc = -l;
9th Feb 2021, 3:57 PM
A͢J
A͢J - avatar
+ 1
Insaf Saidia Can you share your full code? I got problem here if(nboc(l1, l1->suiv) > maxoc) Here l1->suiv should be l1->x I resolved all problem https://code.sololearn.com/cy5k5IY2QB4c/?ref=app
9th Feb 2021, 4:49 PM
A͢J
A͢J - avatar
0
#include <iostream> #include<stdlib.h> using namespace std; struct elt{ int x; elt* suiv; }; typedef elt* liste; //creation d'une liste liste creation(liste l , int n){ int x; liste k; for(int i=0;i<n;i++){ x=rand()%10; k=new elt; k->x=x; k->suiv=l; l=k; } return l; } //affichage de la liste void affichage(liste l){ cout<<"\n"; if(l==NULL)cout<<"\nla liste est vide"; else while(l!=NULL) { l->x; if(l->suiv!=NULL)cout<<"->"; l=l->suiv; } } //longueur de liste int longueur(liste l){ if(l=NULL) return 0; else return 1+ longueur(l->suiv); } // nmb d'occurence int nboc(liste l, int x){ if(l==NULL)return 0; else if(l->x=x)return 1+nboc(l->suiv=l,x); else return nboc(l->suiv=l,x); } liste plusoc(liste l){ int maxoc=-l; liste l1=l; l2=l; while(l1!=NULL){     if(nboc(l1,l1->suiv)>mawoc){l2=l1;     maxoc=nboc(l1,l1->x);     }     l1=l1->suiv; } return l2; } //acces par valeur liste recherche(liste l ,int x){ if(l==NULL) return NULL; else if(l->x==x) return l; else return recherche(l->suiv,x); }
9th Feb 2021, 3:45 PM
Insaf Saidia
Insaf Saidia - avatar
0
Yes it's int maxoc=-1
9th Feb 2021, 4:06 PM
Insaf Saidia
Insaf Saidia - avatar
0
The problem is in: / /supression par poition liste suppos(liste l, int p){ if(p<0)cout<<"position erronee"; else{liste l1=recherchepos(l,p); if(l1!=NULL) l=suppvaleur(l,l1->x);} return l; }
9th Feb 2021, 4:06 PM
Insaf Saidia
Insaf Saidia - avatar