源码:
#include "SqStack.h"
int Merge(int C[],int B[],int nb,int A[],int na){
SqStack stna,stnb;
initStack(stna);
initStack(stnb);
for(int i=0;i<na;i++){
Push(stna,A[i]);
}
for(int i=0;i<nb;i++){
Push(stnb,B[i]);
}
printf("===============Start===============\n");
for(int i=0;i<(na+nb);i++){
if(stna.top!=-1&&stnb.top!=-1){
if(Gettop(stna)>Gettop(stnb)){
C[i] = pop(stna);
}else{
C[i] = pop(stnb);
}
}else if(stna.top==-1&&stnb.top!=-1){
C[i] = pop(stnb);
}else if(stna.top!=-1&&stnb.top==-1){
C[i] = pop(stna);
}
printf("\t\t%d\n",C[i]);
}
printf("===============E N D===============\n");
}
int main(){
int C[11];
int A[5] = {1,3,5,7,9};
int B[8] = {2,4,6,8,10,11,12,23};
Merge(C,B,8,A,5);
}
运行结果: