1、数构复习程序TemplateVoid Bitree:preorder(binode*bt)top=-1;While(bt!=null|top!=-1)while(bt!=null)coutdata;S+top=bt;Bt=bt-lchild;If(top!=-1)bt=stop-;Bt=bt-rchild;TemplateVoid bitree:inorder(binode*bt)top=-1;While(bt!=null|top!=-1)while(bt!=null)s+top=bt;Bt=bt-lchild;If(top!=-1)coutdata;Bt=Stop-;Coutdata;Bt=
2、bt-rchild;TemplateVoid bitree:postorder(binode*bt)top!=-1;While(bt!=null|top!=-1)while(bt!=null)top+;stop.ptr=bt;Stop.flag=1;Bt=bt-lchild;while(top!=-1&stop.flag=2)bt=stop-.ptr;Coutdata;If(top!=-1)stop.flag=2;Bt=stop.ptr-rchild;TemplateVoid count(binode*root)if(root!=null)Count(root-lchild);Count+;C
3、ount(root-rchild);Int level(binode*bt,datatype x,int h)int l;If(bt=null)return 0;Else if(bt-data=x)return h;Elsel=level(bt-lchild,x,h+1);If(l!=0)return (l);Else return(level(bt-rchild,x,h+1);)TemplateVoid preorderprint(binode*rootIf(root!=null)If(!root-lchild&!root-rchild)countdata;Preorder(root-lch
4、ild);Preorder(root-rchild);TemplateInt depth(binode*root)if(root=null)Return 0;Elsehl=depth(bt-lchild);Hr=depth(bt-rchild);Return max(hl,hr)+1;TemplateVoid exchange(binode*bt)if(root!=null)exchange(root-lchild);Exchange(root-rchild);Root-lchildrchild;Int find(int a,int n)for(i-0;in;i+)If(ai=k) break
5、;Return I;Void selectsort(int r,int n)for(i=0;in;i+)index=i;For(j=i+1;jn;j+)If(rindexrj)Index=j;If(index!=i)Rirj;Void max_nmax(int a,int n, int&nmax,int &max)if(a0=ai)max=a0;nmax=ai;Else(max=a1;nmax=a0;)For(i=2;i=max)Nmax=max;Max=ai;Else if(ai=nmax)Nmax=ai;Cout”最大值为:”max”次最大值为:”maxendl;TemplateSeqli
6、st:seqlist(datatype a,int n)if(nmaxsize) throw”参数非法”;For(i=0;in;i+)datai=ai;Length=n;TemplateDatatype seqlist:get(int i)if(ilength)Throw”参数非法”;Else return datai-1;TemplateDatatype seqlist:locate(datatype x)if(i=0;ilength;i+)If(datai=x);return i+1;Return 0;TemplateVoid seqlist:insert(int I,datatype x
7、)if(length=maxsize)throw “上溢”;If(ilength+1)Throw “位置非法”;For(j=length;j=I;j-)dataj=dataj-1;Datai-1=x;Length+;Templatedelete seqlist:delete(int i)if (length=0)Throw”下溢”;If(ilength)throw”位置非法”;X=datai-1;For(j=i;j=length;j+)Dataj-1=dataj;Length-;Return x;TemplateVoid seqlist:printlist()for(i=0;i=length;
8、i+)Coutdatai;Template Void linklist:printlist()p=first-next;While(p!=null)coutdata;p=p-next;TemplateInt linklist:length()p=first-next;count=0;While(p!=null)p=p-next;Count+;Return count;TemplateDatatype linklist:get(int i)p=first-next;Count=1;While(p!=null&countnext;Count+;If(p=null)Throw “位置”;Else r
9、eturn p-data;Template Datatype linklist:ger(int i)p=first-next;Count=1;While(p!=null&countnext;Count+;If(p=null) throw”位置非法”;Else return p-data;TemplateInt linklist:locate(datatype x)p=first-next;Count=1;While(p!=null)if(p-data)=xReturn count;P=p-next;Count+;return 0;Template Void linklist:insert(in
10、t i,datatype x)p=first;count=0;While(p!=null&countnext;Count+;If(p=null)throw“位置非法”;Else s =new node;s -next= p -next;p-next=s;templatelinklist:linklist()First=new node;First-next=null;TemplateLinklist:linklist(datatype a,int n)first=new node;First-next=null;For(i=0;in;i+)s=new node;s-data=ai;s-next
11、=first-next;first-next=s;templatelinklist(datatype a,int n)First=new nodedatatype;R=first;For(i=0;in;i+)s=new node;s-data=ai;r-next=s;r=s;r-next=null;templatedatatype linklist:delete(int i)P=first;Count=0;While(p!=null&countnext;Count+;If(p=null|p-next=null)Throw”位置”;ElseQ=p-next;x=q-data;p-next=q-n
12、ext;delete q;return x;TemplateLinklist:linklist()while(first!=null)q=first;First=first-next;Delete q;TemplateVoid seqstack:pushif(top=stacksize-1)Throw”上溢”;Data+top=x;TemplateDatatype seqstack:pop()if(top=-1)throw “下溢”;X=datatop-;Return x;TemplateVoid linkstack:pushdatatype x)s=new node ;S-data=x;s-
13、next=top;top=s;templatedatatype linkstack:pop()if(top=-1)throw“下溢”;X=top-data;P=top;top=top-next;Delete p;Return x;TemplateVoid cirqueue:enqueuer(datatype x)if(rear+1)%queuesize=front)throw “上溢”;Rear=(rear+1)%queuesize;Datarear=x;TemplateDatatype cirqueue:getqueue()If(rear=front)throw”下溢”;i=(front+1
14、)%queuesize;Return datai;TemplateDatatype cirqueue:dequeuer()If(rear=front)throw “下溢”;Front=(front+1)%queuesize;Return datafront;Templateclass datatypeLinkqueue:linkqueue()s=new queue;s-next=null;front rear=s;TemplateVoid linkqueue:enqueuer(datatype x)s=new node;s-data=x;s-next=null;rear-next=s;rear
15、=s;TemplateDatatype linkqueue:dequeuer()if(rear=front) throw”下溢”;P=front-next;X=p-data;Front-next=p-next;If(p-next=null)Rear=front;Delete p;Return x;TemplateVoid bitree:preorder(binode*bt)if(bt=null)return;Elsecoutdata;Preorder(bt-lchild);Preorder(bt-rchild);TemplateVoid bitree:inorder(binode*bt)If(
16、nt=null)return;ElseInorder(bt-lchild);Coutdata;Inorder(bt-rchild);TemplateVoid bitree:postorder(binode*bt)if(bt=null) return ;ElsePostorder(bt-lchild);Postorder(bt-rchild);Coutdata;TemplateVoid bitree:levelorder()Front=rear=-1;If(root=null)return;Q+rear=root;While(front!=rear)q=q+front;Coutdata;If(q
17、-lchild!=null)Q+rear=q-lchild;If(q-rchild!=null)Q+rear=q-rchid;TemplateBinode*bitree:creat(binode*bt)cinch;If(ch=”#”)bt=null;ElseBt=new node;Bt-data=ch;Bt-lchild=creat(bt-lchild);Bt-rchild=creat(nt-rchild);return bt;TemplateVoid bitree:release(binode*bt)if(bt!=null)release(bt-lchild);Release(bt-rchi
18、ld);Delete bt;TemplateVoid bitree:preorder(binode*bt)top=-1;While(bt!=null|top!=-1)while(bt!=null)coutdata;S+top=bt;Bt=bt-lchild;If(top!=-1)bt=stop-;Bt=bt-rchild;TemplateVoid bitree:inorder(binode*bt)top=-1;While(bt!=null|top!=-1)while(Bt!=null)s+top=bt;Bt=bt-lchild;If(top!=-1)bt=stop-;Coutdata;Bt=b
19、t-rchild;TemplateVoid bitree:postorder(binode*bt)top=-1;While(bt!=null|top!=-1)while(bt!=null)top+;stop.ptr=bt;stop.flag=1;bt=bt-lchild;While(top!=-1&stop.flag=1)bt=stop-.ptr;Coutdata;If(rtop!=-1)stop-.flag=2;Bt=stop.ptr-rchild;我看见3名身着黑衣的年轻枪手进入音乐厅,其中一个枪手向人群开枪,他们的腿部,肩膀,后背不断中枪,人们像多米诺古牌一样倒下,当至少20-25个人被打倒躺在地板上,他们以行刑姿态对伤者,装死者残忍地补枪,全程一言不发,音乐厅陷入绝望的尖叫声中。我全身颤抖地等待他们耗尽子弹再次上膛,然后逃跑。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1