Rewrite requirement 1: Implemented with single-linked list
Overwrite Requirement 2: Delete the linked list node in turn in the destructor
#include <cstdlib>#include<iostream>using namespacestd;structlinknode{intdata; Linknode*next;};classnoprime{friendstructLinknode; Linknode*Head; intN; Public: Noprime (intN1) {N=N1; } voidcreat (); intYesintx) { for(intI=2; i<x/2; i++) if(x%i==0) return 1; return 0; } voidSearch (); voidprint () {Linknode* p=head->Next; while(p) {cout<<p->data<<'\ t'; P=p->Next; } cout<<Endl; } ~Noprime () {Linknode* p=Head; while(Head) {p=Head; Head=head->Next; Delete (p); } }};voidnoprime::creat () {Head=NewLinknode; Head->next=NULL; Linknode* p=Head; intI=N; while(i) {Linknode* newlinknode=NewLinknode; Newlinknode->next=NULL; P->next=Newlinknode; P=Newlinknode; I--; }}voidNoprime::search () {Linknode*p; inti,j,t=1; for(i=3;; i++) {T=1; P=head->Next; for(j=i;j<i+n;j++) {p->data=J; P=p->Next; if(yes (j) = =0) T=0; } if(t==1) Break; }} intMainintargcChar*argv[]) {Noprime num (Ten); Num.creat (); Num. Search (); Num.print (); returnexit_success;}
C + + Programming Practice Guide 1.13 Finding composite rewriting requirements in natural number set implementation