Explain the working of the following code perform rough work .
myList *head,*cur,*previous=NULL;
for(int i=0;i<4;i++)
head=new myList;
head->data=0;
head->next=previous;
for(cur=previous;cur!=NULL;cur=cur->next)
head->data+=1+2*cur->data;
previous=head;
while(previous!=NULL)
cout<<previous->data<<endl;
cur=previous;
previous=previous->next;
delete cur;
myList *head,*cur,*previous=NULL;
//loop through i while i is less than four
for(int i=0;i<4;i++)
head=new myList;
head->data=0;
head->next=previous;
for(cur=previous;cur!=NULL;cur=cur->next)
head->data+=1+2*cur->data;
previous=head;
//loop through while previous is not equal to null
while(previous!=NULL)
cout<<previous->data<<endl;
cur=previous;
previous=previous->next;
//delete current
delete cur;
Comments
Leave a comment