//C语言串的顺序存储表示
//串的堆分配存储表示
//杨鑫
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSTRLEN 255
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
//定义数据元素结的构
typedef int Status;
typedef struct
{
char *ch;
int length;
}HString;
//生成一个其值等于串常量chars的串T
Status StrAssign(HString *T,char *chars)
{
int i,j;
if((*T).ch)
free((*T).ch);
i=strlen(chars);
if(!i)
{
(*T).ch=NULL;
(*T).length=0;
}
else
{
(*T).ch=(char*)malloc(i*sizeof(char));
if(!(*T).ch)
exit(OVERFLOW);
for(j=0;j<i;j++)
(*T).ch[j]=chars[j];
(*T).length=i;
}
return OK;
}
Status StrCopy(HString *T,HString S)
{
int i;
i
数据结构之---C语言实现串的顺序存储
最新推荐文章于 2022-06-01 22:22:47 发布
