C + + Programming Practice Guide 1.6 The Order of n number in the super-long series is implemented by rewriting

Source: Internet
Author: User

Rewrite requirement 1: Rewrite the above program to fit an extra-long integer

Rewrite requirement 2: Rewrite the above program to fit the extra-long sequence

Rewrite requirement 3: N nodes starting at the specified position m in the sequence are re-sorted in descending order

Overwrite requirement 4: Output an extra-long integer of n nodes starting at the specified position m

#include <cstdlib>#include<iostream>#include<string>using namespacestd;structlongintegernode{ Short intdata; Longintegernode*next;};structlinknode{Longintegernode*Plongintegernode; Linknode*next;};classlist{ Public:             structlongintegernode* creat (stringstr); structlinknode* Add (linknode* head,longintegernode*phead); structlinknode* Sortpart (linknode* Head,intMintN); voidOutput (linknode*Head) {Linknode*p; P=head->Next; Longintegernode*Q;  while(p) {Q=p->plongintegernode->Next;  while(q) {cout<<q->data; Q=q->Next; } cout<<Endl; P=p->Next; }             }             voidShow (linknode* Head,intN) {Linknode*p; P=Head; Longintegernode*Q;  while(n) {q=p->plongintegernode->Next;  while(q) {cout<<q->data; Q=q->Next; } cout<<Endl; P=p->Next; N--; }             }     }; Linknode* List::add (linknode* node,longintegernode*phead) {Linknode* newlinknode=NewLinknode; Newlinknode->next=NULL; Newlinknode->plongintegernode=Phead; Node->next=Newlinknode; Node=Newlinknode; returnnode;} Longintegernode* List::creat (stringstr) {       stringS=STR.SUBSTR (0,1); intI=1; Longintegernode* phead=NewLongintegernode; Phead->next=NULL; Longintegernode*p; P=Phead;  while(S.length ()) {Longintegernode* newlongintegernode=NewLongintegernode; Newlongintegernode->next=NULL; Newlongintegernode->data=atoi (S.c_str ()); P->next=Newlongintegernode; P=Newlongintegernode; if(S.length () <1)            returnPhead; S=str.substr (I,1); I=i+1; }       returnPhead;} Linknode* List::sortpart (linknode* Head,intMintN) {    intx=m; inty=N; inttemp; Linknode* p=head->Next; Linknode*Q; Longintegernode* t,*s;  while(x) {p=p->Next; X--; } q=p;  while(y) { for(t=p->plongintegernode;t!=null;t=t->next) {        for(s=t->next;s!=null;s=s->next) {                       if(t->data<s->data) {Temp=t->data; T->data=s->data; S->data=temp; } }} p=p->Next; Y--; }    returnq;}intMainintargcChar*argv[])    {List List; Linknode* head=NewLinknode; Head->next=NULL; Linknode*sort; Linknode*tail; Tail=Head; stringstr; CIN>>str;  while(str!="Exit") {Longintegernode*Phead; Phead=list.creat (str); Tail=List.add (Tail,phead); CIN>>str; } Sort=list.sortpart (Head,1,2);    List.output (Head); cout<<"outputs the specified sort sequence"<<Endl; List.show (Sort,2); System ("PAUSE"); returnexit_success;}

C + + Programming Practice Guide 1.6 The Order of n number in the super-long series is implemented by rewriting

Related Article

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.