📄 d.h
字号:
#include<iostream.h>
#include<stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OVERFLOW -2
#define OK 1
typedef struct
{
int * elem;
int length;
int listsize;
}
list;
void listtraverse(list L)
{//遍历线性表
if(L.elem)
{
for(int j=0;j<L.length;j++)
{
cout<<L.elem[j]<<endl;
}
}
else exit(OVERFLOW);
}
void mergelist(list la,list lb,list & lc)
{//有序表合并
lc.listsize=lc.length=la.length+lb.length;
lc.elem=new int[lc.listsize];
int * p,* q,* k;
p=la.elem;
q=lb.elem;
k=lc.elem;
while(p<=&la.elem[la.length-1]&&q<=&lb.elem[lb.length-1])
{
if(*p>=*q)
*k++=*q++;
else
*k++=*p++;
}
while(p<=&la.elem[la.length-1])
{
*k++=*p++;
}
while(q<=&lb.elem[lb.length-1])
{
*k++=*q++;
}
}
void main()
{
int a[4]={3,5,8,11};
int b[7]={2,6,8,9,11,15,20};
list la={a,4,4};
list lb={b,7,7};
list lc;
mergelist(la,lb,lc);
listtraverse(lc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -