Answer to Question #242480 in C++ for rumia

Question #242480

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;

  


1
Expert's answer
2021-09-26T12:27:52-0400
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;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS