Collapse!!! Everybody help me to see where is the problem??? Reverse of linked list

Source: Internet
Author: User

When I was doing a pat today, there was this one.

The basic method is to do with the list, and use the array to do the chant, the habitual first with the array to do, the result is a problem

1#include <iostream>2#include <string.h>3 using namespacestd;4 5 intMain ()6 {7     intcount, Renum;8     stringadd;9Cin>>add>>count>>Renum;Ten     stringAdd1[count],add2[count],madd1[count],madd2[count]; One     intMnum[count],num[count]; A      for(intI=0; i<count;i++) -     { -Cin>>add1[i]>>num[i]>>Add2[i]; the     } -      for(intI=0; i<count;i++) -     { -  +          for(intj=0; j<count;j++) -        { +            if(add1[j]==add) A            { atMadd1[i] =Add1[j]; -mnum[i]=Num[j]; -Madd2[i] =Add2[j]; -Add=Madd2[i]; -                 Break; -            } in        } -     } to     inttemp=0; +     intfake =count; -      while(count-renum>=0) the     { *          for(intI= temp,j=temp+renum-1; i<=temp+renum-1; i++,j--) $         {Panax NotoginsengAdd1[i] =Madd1[j]; -Num[i] =Mnum[j]; the         } +count-=Renum; Atemp=temp+Renum; the     } +      for(inti=temp;i<fake;i++) -     { $  $Add1[i] =Madd1[i]; -Num[i] =Mnum[i]; -     } the      for(intI=0; i<fake-1; i++) -     {Wuyiadd2[i]=add1[i+1]; the     } -add2[fake-1] ="-1"; Wu      for(intI=0; i<fake;i++) -     { Aboutcout<<add1[i]<<" "<<num[i]<<" "<<add2[i]<<Endl; $     } -     return 0; -}

Please disregard my variable naming habits

The result is

Run Timeout I can also understand, after all, it is possible that the complexity is O (n*n), I will find a way to solve.

But what is wrong with the answer? What special circumstances did I not consider? Please find the person to teach Ah!! Thanks, man.

Above

Collapse!!! Everybody help me to see where is the problem??? Reverse of linked list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.