数构复习程序.docx
《数构复习程序.docx》由会员分享,可在线阅读,更多相关《数构复习程序.docx(14页珍藏版)》请在冰豆网上搜索。
数构复习程序
Template
VoidBitree:
:
preorder(binode*bt)
{top=-1;
While(bt!
=null||top!
=-1)
{while(bt!
=null){cout<data;
S[++top]=bt;
Bt=bt->lchild;}
If(top!
=-1)
{bt=s[top--];
Bt=bt->rchild;
}}
Template
Voidbitree:
:
inorder(binode*bt)
{top=-1;
While(bt!
=null||top!
=-1)
{while(bt!
=null)
{s[++top]=bt;
Bt=bt->lchild;}
If(top!
=-1)
{cout<data;
Bt=S[top--];
Cout<data;
Bt=bt-rchild;
}
Template
Voidbitree:
:
postorder(binode*bt)
{top!
=-1;
While(bt!
=null||top!
=-1)
{while(bt!
=null)
{top++;
s[top].ptr=bt;
S[top].flag=1;
Bt=bt->lchild;}
while(top!
=-1&&s[top].flag==2)
{bt=s[top]--.ptr;
Cout<data;
}
If(top!
=-1)
{s[top].flag=2;
Bt=s[top].ptr->rchild;}
Template
Voidcount((binode*root)
{if(root!
=null)
Count(root->lchild);
Count++;
Count(root->rchild);
}
Intlevel(binode*bt,datatypex,inth)
{intl;
If(bt==null)return0;
Elseif(bt->data==x)returnh;
Else{l=level(bt->lchild,x,h+1);
If(l!
=0)return(l);
Elsereturn(level(bt->rchild,x,h+1);)
}
Template
Voidpreorderprint(binode*root>
If(root!
=null)
If(!
root->lchild&&!
root->rchild)
{count<data;
Preorder(root->lchild);
Preorder(root->rchild);
}
Template
Intdepth(binode*root)
{if(root==null)
Return0;
Else{hl=depth(bt->lchild);
Hr=depth(bt->rchild);
Returnmax(hl,hr)+1;
}
Template
Voidexchange(binode*bt)
{if(root!
=null)
{exchange(root->lchild);
Exchange(root->rchild);
Root->lchildrchild;
}
Intfind(inta[],intn)
{for(i-0;iIf(a[i]==k)break;
ReturnI;
}
Voidselectsort(intr[],intn)
{for(i=0;i{index=i;
For(j=i+1;jIf(r[index]Index=j;
If(index!
=i)
R[i]<->r[j];
}
Voidmax_nmax(inta[],intn,int&nmax,int&max)
{if(a[0]>=a[i]){max=a[0];nmax=a[i];}
Else(max=a[1];nmax=a[0];)
For(i=2;iIfa[i]>=max)
Nmax=max;
Max=a[i];}
Elseif(a[i]>=nmax)
Nmax=a[i];
Cout<<”最大值为:
”<”<}
Template
Seqlist:
:
seqlist(datatypea[],intn)
{if(n>maxsize)throw”参数非法”;
For(i=0;i{data[i]=a[i];
Length=n;}
Template
Datatypeseqlist:
:
get(inti)
{if(i<1&&i>length)
Throw”参数非法”;
Elsereturndata[i-1];
}
Template
Datatypeseqlist:
:
locate(datatypex)
{if(i=0;iIf(data[i]==x);return[i+1];
Return0;
}
Template
Voidseqlist:
:
insert(intI,datatypex)
{if(length>=maxsize)throw“上溢”;
If(i<1||i>length+1)
Throw“位置非法”;
For(j=length;j>=I;j--)
{data[j]=data[j-1];
Data[i-1]=x;
Length++;
}
Template
deleteseqlist:
:
delete(inti)
{if(length==0)
Throw”下溢”;
If(i<1||i>length)throw”位置非法”;
X=data[i-1];
For(j=i;j<=length;j++)
Data[j-1]=data[j];
Length--;
Returnx;}
Template
Voidseqlist:
:
printlist()
{for(i=0;i<=length;i++)
Cout<}
Template
Voidlinklist:
:
printlist()
{p=first->next;
While(p!
=null)
{cout<data;
p=p->next;}
}}
Template
Intlinklist:
:
length(){p=first->next;count=0;
While(p!
=null){p=p->next;
Count++;}
Returncount;}
Template
Datatypelinklist:
:
get(inti)
{p=first->next;
Count=1;
While(p!
=null&&count
{p=p->next;
Count++;}
If(p==null)
Throw“位置”;
Elsereturnp->data;
}
Template
Datatypelinklist:
:
ger(inti)
{p=first->next;
Count=1;
While(p!
=null&&count
{p=p->next;
Count++;}
If(p==null)throw”位置非法”;
Elsereturnp->data;
}
Template
Intlinklist:
:
locate(datatypex)
{p=first->next;
Count=1;
While(p!
=null)
{if(p->data)==x
Returncount;
P=p->next;
Count++;
}return0;
}
Template
Voidlinklist:
:
insert(inti,datatypex)
{p=first;count=0;
While(p!
=null&&count{p=p->next;
Count++;}
If(p==null)throw“位置非法”;
Else{s=newnode;
s->next=p->next;
p->next=s;}}
template
linklist:
:
linklist()
{
First=newnode;
First->next==null;}
Template
Linklist:
:
linklist(datatypea[],intn)
{first=newnode;
First->next==null;
For(i=0;i{s=newnode;
s->data=a[i];
s->next=first->next;
first->next=s;}
template
linklist(datatypea[],intn)
{
First=newnode《datatype>;
R=first;
For(i=0;i{s=newnode;
s->data=a[i];
r->next=s;r=s;
}
r->next=null;}
template
datatypelinklist:
:
delete(inti)
{
P=first;
Count=0;
While(p!
=null&&count{p=p->next;
Count++;}
If(p==null||p->next==null)
Throw”位置”;
Else{
Q=p->next;
x=q->data;
p->next=q->next;
deleteq;
returnx;
}}
Template
Linklist:
:
~linklist()
{while(first!
=null)
{q=first;
First=first->next;
Deleteq;
]
Template
Voidseqstack:
:
push
{if(top==stacksize-1)
Throw”上溢”;
Data[++top]=x;
}
Template
Datatypeseqstack:
:
pop()
{if((top==-1)throw“下溢”;
X=data[top--];
Returnx;
}
Template
Voidlinkstack:
:
push{s=newnode;
S->data=x;
s->next=top;
top=s;}
template
datatypelinkstack:
:
pop()
{if(top==-1)throw“下溢”;
X=top->data;
P=top;top=top->next;
Deletep;
Returnx;
}
Template
Voidcirqueue:
:
enqueuer(datatypex)
{if((rear+1)%queuesize==front)throw“上溢”;
Rear==(rear+1)%queuesize;
Data[rear]=x;
}
Template
Datatypecirqueue:
:
getqueue()
{
If((rear==front)throw”下溢”;
i=(front+1)%queuesize;
Returndata[i];
}
Template
Datatypecirqueue:
:
dequeuer()
{
If((rear==front)throw“下溢”;
Front=(front+1)%queuesize;
Returndata[front];
}
Template《classdatatype>
Linkqueue:
:
linkqueue()
{s=newqueue;
s->next=null;
frontrear=s;
}
Template
Voidlinkqueue:
:
enqueuer(datatypex)
{s=newnode<>;
s->data=x;
s->next=null;
rear->next=s;
rear=s;
}
Template
Datatypelinkqueue:
:
dequeuer()
{if((rear==front)throw”下溢”;
P=front->next;
X=p->data;
Front->next=p->next;
If(p->next==null)
Rear=front;
Deletep;
Returnx;
}
Template
Voidbitree:
:
preorder(binode*bt)
{if(bt==null)return;
Else{cout<data;
Preorder(bt->lchild);
Preorder(bt->rchild);
}}
Template
Voidbitree:
:
inorder(binode*bt)
{
If(nt==null)return;
Else{
Inorder(bt->lchild);
Cout<data;
Inorder(bt->rchild);
}
Template
Voidbitree:
:
postorder(binode*bt)
{if(bt==null)return;
Else{
Postorder(bt->lchild);
Postorder(bt->rchild);
Cout<data;}
Template
Voidbitree:
:
levelorder(){
Front=rear=-1;
If(root==null)return;
Q[++rear]=root;
While(front!
=rear)
{q=q[++front];
Cout<data;
If(q->lchild!
=null)
Q[++rear]=q->lchild;
If(q->rchild!
=null)
Q[++rear]=q->rchid;
}}
Template
Binode*bitree:
:
creat(binode*bt)
{cin>>ch;
If(ch==”#”)bt=null;
Else{
Bt=newnode<>;
Bt->data=ch;
Bt->lchild=creat(bt->lchild);
Bt->rchild=creat(nt->rchild);
}returnbt;
}
Template
Voidbitree:
:
release(binode*bt)
{if(bt!
=null)
{release(bt->lchild);
Release(bt->rchild);
Deletebt;
}
Template
Voidbitree:
:
preorder(binode*bt)
{top=-1;
While(bt!
=null||top!
=-1)
{while(bt!
=null)
{cout<data;
S[++top]=bt;
Bt=bt->lchild;
}
If(top!
=-1)
{bt=s[top--];
Bt=bt->rchild;
}
Template
Voidbitree:
:
inorder(binode*bt)
{top=-1;
While(bt!
=null||top!
=-1)
{while(Bt!
=null)
{s[++top]=bt;
Bt=bt->lchild;
}
If(top!
=-1)
{bt=s[top--];
Cout<data;
Bt=bt->rchild;
}}
Template
Voidbitree:
:
postorder(binode*bt)
{top=-1;
While(bt!
=null||top!
=-1)
{while(bt!
=null)
{top++;
s[top].ptr=bt;
s[top].flag=1;
bt=bt->lchild;
}
While(top!
=-1&&s[top].flag==1)
{bt=s[top--].ptr;
Cout<data;
}
If(rtop!
=-1)
{s[top--].flag=2;
Bt=s[top].ptr->rchild;
}}
我看见3名身着黑衣的年轻枪手进入音乐厅,其中一个枪手向人群开枪,他们的腿部,肩膀,后背不断中枪,人们像多米诺古牌一样倒下,当至少20-25个人被打倒躺在地板上,他们以行刑姿态对伤者,装死者残忍地补枪,全程一言不发,音乐厅陷入绝望的尖叫声中。
我全身颤抖地等待他们耗尽子弹再次上膛,然后逃跑。