typedef struct
{char *str;
int size;
}String;
void SetString(String *S);
int StrSize(String *S);
int StrEmpty(String *S);
char StrGetData(String *S,int pos);
int StrCompare(String *S,String *T);
char *Trans(String *S);
void StrAssign(String *S,char *cs);
void StrConcat(String *S,String *S1,String *S2);
void SubString(String *T,String *S,int pos,int count);
void StrInsert(String *S,char *cs,int pos);
void StrInsert1(String *S,String *CS,int pos);
void StrDelete(String *S,int pos,int count);
void FreeString(String *S);
void ClearString(String *S);
void SetString(String *S)
{S->str=(char *)malloc(sizeof(char));
if(S->str==NULL)
{printf("overflow");
exit(1);
}
*(S->str)='\0';
S->size=0;
}
int StrSize(String *S)
{return(S->size);
}
int StrEmpty(String *S)
{if(S->size==0)
return(1);
return(0);
}
char StrGetData(String *S,int pos)
{if(pos<0||pos>S->size-1)
{printf("pos in StrGetData is illegal!");
exit(1);
}
return(S->str[pos]);
}
int StrCompare(String *S,String *T)
{return(strcmp(S->str,T->str));
}
char *Trans(String *S)
{return(S->str);
}
void StrAssign(String *S,char *cs)
{int n;
free(S->str);
n=strlen(cs)+1;
S->str=(char *)malloc(n*sizeof(char));
if(S->str==NULL)
{printf("overflow");
exit(1);
}
strcpy(S->str,cs);
S->size=n-1;
}
void StrConcat(String *S,String *S1,String *S2)
{int n;
free(S->str);
n=S1->size+S2->size+1;
S->str=(char *)malloc(n*sizeof(char));
if(S->str==NULL)
{printf("overflow");
exit(1);
}
strcpy(S->str,S1->str);
strcat(S->str,S2->str);
S->size=n-1;
}
void SubString(String *T,String *S,int pos,int count)
{int i,charsleft;
char *p,*q;
if(pos<0||pos>S->size-1)
{printf("Pos in SubString is illegal!\n");
exit(1);
}
if(count<0)
{printf("Count in SubString is illegal!\n");
exit(1);
}
free(T->str);
charsleft=S->size-pos;
if(count>charsleft)
count=charsleft;
T->str=(char *)malloc((count+1)*sizeof(char));
if(T->str==NULL)
{printf("overflow");
exit(1);
}
p=T->str;
q=S->str+pos;
for(i=1;i<=count;i++)
*p++=*q++;
*p='\0';
T->size=count;
}
void StrInsert(String *S,char *cs,int pos)
{int n,i,charsleft;
char *temp,*p,*q;
if(pos<0||pos>S->size)
{printf("Pos in StrInsert is illegal!\n");
exit(1);
}
n=S->size+1;
temp=(char *)malloc(n*sizeof(char));
if(temp==NULL)
{printf("overflow");
exit(1);
}
strcpy(temp,S->str);
free(S->str);
n=strlen(temp)+strlen(cs)+1;
S->str=(char *)malloc(n*sizeof(char));
if(S->str==NULL)
{ printf("overflow");
exit(1);
}
strcpy(S->str,temp);
p=S->str+strlen(temp);
q=S->str+n-1;
charsleft=strlen(temp)-pos+1;
for(i=1;i<=charsleft;i++)
*q--=*p--;
p=S->str+pos;
q=cs;
while(*q!='\0')
*p++=*q++;
S->size=n-1;
free(temp);
}
void StrInsert1(String *S,String *CS,int pos)
{ int n,i,charsleft;
char *temp,*p,*q;
if(pos<0||pos>S->size)
{ printf("Pos in StrInsert is illegal!\n");
exit(1);
}
n=S->size+1;
temp=(char *)malloc(n*sizeof(char));
if(temp==NULL)
{ printf("overflow");
exit(1);
}
strcpy(temp,S->str);
free(S->str);
n=S->size+CS->size+1;
S->str=(char *)malloc(n*sizeof(char));
if(S->str==NULL)
{ printf("overflow");
exit(1);
}
strcpy(S->str,temp);
p=S->str+strlen(temp);
q=S->str+n-1;
charsleft=strlen(temp)-pos+1;
for(i=1;i<=charsleft;i++)
*q--=*p--;
p=S->str+pos;
q=CS->str;
while(*q!='\0')
*p++=*q++;
S->size=n-1;
free(temp);
}
void StrDelete(String *S,int pos,int count)
{ int i,n,charsleft;
char *temp,*p,*q;
if(pos<0||pos>S->size-1)
{ printf("Pos in StrDelete is illegal!\n");
exit(1);
}
if(count<0)
{ printf("Count in StrDelete is illegal!\n");
exit(1);
}
if(count==0)
return;
n=S->size+1;
temp=(char *)malloc(n*sizeof(char));
if(temp==NULL)
{ printf("overflow");
exit(1);
}
strcpy(temp,S->str);
if(count>=strlen(temp)-pos)
temp[pos]='\0';
else
{ p=temp+pos;
q=temp+pos+count;
while(*q!='\0')
*p++=*q++;
*p='\0';
}
free(S->str);
n=strlen(temp)+1;
S->str=(char *)malloc(n*sizeof(char));
if(S->str==NULL)
{ printf("overflow");
exit(1);
}
strcpy(S->str,temp);
S->size=n-1;
free(temp);
}
void ClearString(String *S)
{ free(S->str);
S->str=(char *)malloc(sizeof(char));
if(S->str==NULL)
{ printf("overflow");
exit(1);
}
*(S->str)='\0';
S->size=0;
}
void FreeString(String *S)
{ free(S->str);
}
没有合适的资源?快使用搜索试试~ 我知道了~
VC++ 与数据结构电子书
共52个文件
h:33个
x32:14个
ini:3个
需积分: 0 84 下载量 71 浏览量
2009-05-11
15:14:27
上传
评论
收藏 3.57MB RAR 举报
温馨提示
随着面向对象技术的发展,传统的数据结构课程面临着融入新内容,提升到面向对象数据结构、算法及软件工程的高度的重大挑战。
资源推荐
资源详情
资源评论
收起资源包目录
c++与c数据结构.rar (52个子文件)
c++与c数据结构
h_file
PRINTQ.H 1KB
DLLIST.H 2KB
NODE.H 631B
AVLNODE.H 537B
BANK.H 3KB
MAKETREE.H 643B
STR.H 5KB
AVLTREE.H 3KB
HUFMHEAP.H 2KB
EVDNODE.H 1KB
LQUEUE.H 2KB
MAKECT.H 741B
TNODE.H 481B
STACK1.H 1KB
cTree.h 2KB
CNODE.H 463B
_desktop.ini 9B
DNODE.H 1010B
GRAPH.H 2KB
PTRSTACK.H 1KB
PTRQUEUE.H 1KB
MAKEG.H 623B
HUFMPRIN.H 2KB
Queen.h 528B
QUEUE.H 1KB
SEQLIST.H 2KB
Print.h 2KB
PTR_TAG.H 1KB
STACK.H 1KB
COUNT.H 2KB
BSTREE.H 2KB
Evdllist.h 3KB
LLIST.H 2KB
HEAP.H 2KB
_desktop.ini 9B
xtras
wmfview.x32 37KB
wavread.x32 55KB
CROSSIN.X32 151KB
mixview.x32 47KB
GIFIMP.X32 53KB
PNGIMP.X32 208KB
PS3IMP.X32 65KB
COVERIN.X32 154KB
viewsvc.x32 92KB
JPEGIMP.X32 92KB
bmpview.x32 45KB
DIRTRANS.X32 68KB
_desktop.ini 9B
MIX32.X32 117KB
bmpview.x16 38KB
COVEROUT.X32 153KB
c_stru.exe 4.95MB
共 52 条
- 1
资源评论
fire_moon
- 粉丝: 0
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功