⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 algorithm_two_seven.cpp

📁 数据结构的的源码
💻 CPP
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define Elemtype int

typedef struct{
   Elemtype *elem;
   int Lenth;
}Sqlist;


char InitList(Sqlist &L,char B)
{
  L.elem=(Elemtype *)malloc(10*sizeof(Elemtype));
  if(L.elem==NULL)return 0;
  L.Lenth=10;
  for(int i=0;i<10;i++)
  {
     L.elem[i]=B++;  
  }
}

void Mergelist(Sqlist La,Sqlist Lb,Sqlist &Lc)
{
 Elemtype *P1,*P2,*P3,*P1_Last,*P2_Last;
 P1=La.elem;
 P2=Lb.elem;
 P1_Last=La.elem+La.Lenth-1;
 P2_Last=Lb.elem+Lb.Lenth-1;

 Lc.Lenth=(La.Lenth+Lb.Lenth);
 P3=Lc.elem=(Elemtype *)malloc(Lc.Lenth*sizeof(Elemtype));
while((P1<=P1_Last)&&(P2<P2_Last))
{
  if(*P1<*P2)*P3++=*P1++;
  else
     *P3++=*P2++; 
}
while(P2<=P2_Last)
    *P3++=*P2++;
while(P1<=P1_Last)
    *P3++=*P1++;  

}

void main()
{
	int i=0;
   Sqlist La,Lb,Lc;
   InitList(La,'A');
   InitList(Lb,'a');
   Mergelist(La,Lb,Lc);
  while(i<Lc.Lenth)
  {printf("%c\n",Lc.elem[i]);
  i++;}
   printf("%d\n",Lc.Lenth);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -