Make Deep Copy of list

Segmentation fault in my code. Please help!

Hey @kshitijkameria
please share ur code

#include #include using namespace std; class Node{ public: int data; Node* next; Node(int x){ data=x; next=NULL; } }; int main() { int n; cin>>n; Node *head=NULL; Node *temp=head; int x,y=0; vector v; vector shit; for(int i=0; i<n; i++){ cin>>x; if(head==NULL){ head=temp= new Node(x); } else{ temp->next=new Node(x); temp=temp->next; } shit.push_back(x); cin>>y; v.push_back(y); } temp=head; int i=0; cout<< “Old List: “; while(temp!=NULL){ int z=v[i]; cout<<”(”<data<<","; if(z==0){ cout<<shit[0]<<") “; }else if(z==NULL){ cout<<“NULL”<< “) “; } else{ cout<<shit[z]<<”) “; } i++; temp=temp->next; } temp=head; cout<< endl; cout<< “Copied List: “; i=0; while(temp!=NULL){ int z=v[i]; cout<<”(”<data<<”,”; if(z==0){ cout<<shit[0]<<”) "; }else if(z==NULL){ cout<<“NULL”<< ") “; } else{ cout<<shit[z]<<”) "; } i++; temp=temp->next; } return 0; }

Hey @kshitijkameria
Please share it in Coding blocks IDE
Its difficult to understand thisway

How to share the code on coding blocks ide?

Hey @kshitijkameria
Go here


copy your code with proper indentation
Press ctrl +s
And then share the url