Rewrite requirements 1: Change to be suitable for processing super-long integers
#include <cstdlib>#include<iostream>#include<string>using namespacestd;structlinknode{ Short intdata; Linknode*next;};classstr{stringstr; Public: STR (stringx) {str=x; } structlinknode*itoa (); structlinknode* Reverse (linknode*phead); voidPrint (linknode*phead) {Linknode* p=Phead; P=p->Next; cout<<"n="; while(p) {cout<<p->data; P=p->Next; } cout<<Endl; }};structlinknode*Str::itoa () {Linknode* phead=NewLinknode; Phead->next=NULL; Linknode*p; P=Phead; intI=0; strings; intX=atoi (Str.substr (i,1). C_STR ()); while(1) {Linknode* newlinknode=NewLinknode; Newlinknode->next=NULL; Newlinknode->data=x; P->next=Newlinknode; P=Newlinknode; S=str.substr (++i,1). C_str (); if(s.length () = =0) returnPhead; X=atoi (S.c_str ()); } returnPhead; }structlinknode* Str::reverse (linknode*phead) {Linknode*p,*Q; Linknode*T; P=phead->Next; Q=phead->next->Next; while(q) {T= q->Next; Q->next =p; P=Q; Q=T; } phead->next->next=NULL; Phead->next=p; returnPhead;} intMainintargcChar*argv[]) { stringN; Linknode*Phead; cout<<"Input N:"; CIN>>N; Str STR (n); Phead=Str.itoa (); //Phead=str.reverse (phead);Str.print (Phead); System ("PAUSE"); returnexit_success;}
C + + Programming Practice Guide 1.4 positive integer conversion to string rewrite requirements implementation