已知线性表La和Lb中的数据元素按值非递减有序排列,现要求La和Lb归并排序为Lc
我想知道我这段rank中a和b表的元素为什么只传递了1和2给c,后续就不在执行了?
代码如下
#include <stdio.h>
#define MAX 100
typedef int Status;
int e;
typedef struct {
int data[MAX];
int length;
}Slist;
int insert(Slist *L, int i, int e) {
if (i<1 || i>L->length + 1)
return 0;
for (int j = L->length; j >= i; j--)
L->data[j] = L->data[j-1];
L->data[i - 1] = e;
L->length++;
return true;
}
Status GetElem(Slist* L, int i,int& e){
if (i<0 || i>L->length)
return 0;
e = L->data[i];
return e;
}
Status locate(Slist L,int e) {
for (int i = 0; i < L.length; i++)
if (L.data[i] == e)
return i + 1;
return 0;
}
int length(Slist L){
return L.length;
}
Status rank(Slist a,Slist b ) {
int ea;
int eb;
Slist c{};
c.length = 0;
for (int k = 0; k < (a.length+b.length); k++) {
GetElem(&a, k, ea);
GetElem(&b, k, eb);
if (ea <= eb);
insert(&c, k+1, ea);
insert(&c, k+2, eb);
return 0;
}
}
int main() {
Slist La{};
La.length = 0;
Slist Lb{};
Slist Lc{};
Lb.length = 0;
Lc.length = 0;
insert(&La, 1, 1);
insert(&La, 2, 7);
insert(&La, 3, 8);
insert(&Lb, 1, 2);
insert(&Lb, 2, 4);
insert(&Lb, 3, 6);
insert(&Lb, 4, 8);
insert(&Lb, 5, 10);
insert(&Lb, 6, 11);
rank(La,Lb);
}
rank函数的运行结果: