数据结构预算法。链式串基本操作示例

这篇博客展示了如何使用链式串进行一系列基本操作,包括初始化、显示、比较、连接、子串提取、索引查找、插入、删除以及替换等。通过C++代码实例,深入理解数据结构中的链式串概念。
摘要由CSDN通过智能技术生成
#include "iostream"
#include "malloc.h"
using namespace std;


#define MaxSize 100
typedef struct node{
char data;
struct node *next;
}LinkString;


void Assign(LinkString *&s,char str[]){
int i=0;
LinkString *p,*tc;
s=(LinkString*)malloc(sizeof(LinkString));
tc=s;
while(str[i]!='\0'){
p=(LinkString*)malloc(sizeof(LinkString));
p->data=str[i];
tc->next=p;tc=p;
i++;
}
tc->next=NULL;
}


void Destroystr(LinkString *&s){
LinkString *pre=s,*p=pre->next;
while(p){
free(pre);
pre=p;p=p->next;
}
free(pre);
}


void StrCopy(LinkString *&s,LinkString *t){
LinkString *p=t->next,*q,*tc;
s=(LinkString*)malloc(sizeof(LinkString));
tc=s;
while(p){
q=(LinkString*)malloc(sizeof(LinkString));
q->data=p->data;
tc->next=q;tc=q;
p=p->next;

}
tc->next=NULL;
}


int StrLength(LinkString *s){
int n=0;
LinkString *p=s->next;
while(p){
n++;
p=p->next;
}

return n;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值