Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nodo{
- int info;
- nodo * next;
- nodo ( int a = 0, nodo* b = 0){
- info = a;
- next = b;
- }//costruttore
- };//nodo
- nodo* inserisci(){
- int x;
- cout<<"Inserisci un valore da inserire in lista: "; cin>>x; cout<<endl;
- if(x == -1)
- return 0;
- else
- return new nodo(x,inserisci());
- }
- void stampa(nodo * P){
- if(!P)
- return;
- else{
- cout<<P->info<<" ";
- return stampa(P->next);
- }
- }//stampa
- nodo * alt_mix(nodo *P, nodo *Q){
- nodo * temp;
- if( !P || !Q)
- return 0;
- else{
- if(P && Q ){
- if(!P->next){
- P->next = Q;
- return 0;
- }
- temp = Q->next;
- Q->next = P->next;
- P->next = Q;
- return alt_mix(Q->next, temp);
- }
- }//!caso base
- }//alt_mix
- main(){
- cout<<"Inserisci la prima lista . . ."<<endl;
- nodo * prima = inserisci();
- cout<<"Inserisci la seconda lista . . . "<<endl;
- nodo * seconda = inserisci();
- nodo * alt = alt_mix(prima,seconda);
- stampa(alt);
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement