Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct nodo{
- int info;
- nodo* next;
- nodo(int a=0, nodo* b=0){
- info=a; next=b;
- }
- };
- //crea nodo
- nodo* crea(int dim, ifstream & IN){
- if(dim==0){
- return NULL;
- }
- nodo* temp;
- temp= new nodo;
- IN >> temp-> info;
- temp-> next = crea(dim-1, IN);
- return temp;
- }
- //cancella nodo
- nodo* del_z(nodo* n, int z){
- nodo * temp;
- temp->info =z;
- if ( n->next != temp) {
- return NULL;
- }
- while(n->next!=temp){
- n=n->next;
- }
- n->next=n->next;
- delete temp;
- del_z(n, z);
- return n;
- }
- //stampa
- void stampa(ofstream & OUT, int dim, nodo* x){
- if (dim==0){
- OUT<<" Fine";
- return;
- }
- else if(dim==1){
- x->next;
- OUT<<x->info;
- OUT<<endl<<" Fine";
- return;
- }
- OUT<< x->info;
- OUT<<"->";
- stampa(OUT, dim-1, x->next);
- }
- //main del programma
- int main(){
- ifstream IN("input");
- ofstream OUT("output");
- int dim;
- int z;
- IN>>dim;
- IN>>z;
- nodo* n = crea(dim, IN);
- nodo* x = del_z(n, z);
- stampa(OUT, dim, x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement