Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void inserisciXdopoY(plista p, int x, int y) {
- plista prec = p;
- plista corr = p->next;
- if (conta(prec,y)==0) { //inserisco il nodo x in coda
- while(corr->next) {
- prec = prec->next;
- corr = corr-> next;
- }
- corr = (plista) malloc(sizeof(lista));
- corr->info=x;
- prec=prec->next;
- prec->next=corr;
- corr->next=NULL;
- }
- else {
- while (corr->next) {
- if (prec->info==y) {
- corr = (plista) malloc(sizeof(lista));
- corr->info=x;
- corr->next = prec->next;
- prec->next = corr;
- prec=prec->next;
- corr=corr->next;
- }
- else {
- prec=prec->next;
- corr=corr->next;
- }
- }
- //Controllo dell'ultimo nodo
- if(corr->info==y) {
- corr = (plista) malloc(sizeof(lista));
- corr->info=x;
- prec=prec->next;
- prec->next=corr;
- corr->next=NULL;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment