高分求解编辑距离问题(算法导论中文正版教材P218习题15-3)!!!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/16 06:05:07
程序要简洁明了,必须是原创!!!!!并带有详细注释及程序说明 选为答案后还有更多加分!!!!

#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 50

#define STACK_INIT_SIZE 50
#define STACK_INCREAMENT 10

typedef int ElemType;

int xLength,yLength;

enum cost{copy=1,replace=4,del=2,insert=3,twiddle=4,kill=5};

struct MyStack{
ElemType *base;//栈底
ElemType *top;//栈顶
int size;//栈的大小
};//栈类型

MyStack s;

bool InitStack(MyStack &s)
{
s.base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!s.base) exit(-1);
s.top=s.base;
s.size=STACK_INIT_SIZE;
return true;
}//初始化栈

bool Push(MyStack &s,ElemType e)
{
if((s.top-s.base)>=s.size) {
s.base=(ElemType *)malloc((s.size+STACK_INCREAMENT)*sizeof(ElemType));
if(!s.base) exit(-1);
s.top=s.base+s.size;
s.size+=STACK_INCREAMENT;
}
*s.top++=e;
return true;
}//入栈

boo