因为插入,删除,替换操作代码比较长,所以放在下一篇说明链串节点类型
typedef struct Node { char data; struct Node* next; }linkstrnode;
字符串赋值为链串
void strassign(linkstrnode*& L, char str[]) { linkstrnode* r, * s; L = (linkstrnode*)malloc(sizeof(linkstrnode)); r = L; for (int i = 0; str[i] != 'n'; i++) { s = (linkstrnode*)malloc(sizeof(linkstrnode)); s->data[i] = str[i]; r->next = s; r = s; } r->next = NULL; }
销毁串
void destoryste(linkstrnode*& L) { linkstrnode* r, * s; r = L; s = L->next; while ( s != NULL ) { free(r); r = s; s = r->next; } free(r); }
复制串
void strcopy(linkstrnode*& t, linkstrnode* s) { linkstrnode* p = s->next, * q, * r; t = (linkstrnode*)malloc(sizeof(linkstrnode)); r = t; while ( p != NULL ) { q = (linkstrnode*)malloc(sizeof(linkstrnode)); q->data = p->data; r->next = q; r = q; p = p->next; } r->next = NULL; }
判断串相等
void strequal(linkstrnode* s, linkstrnode* t) { linkstrnode* p = s->next, * q = t->next; while ( p != NULL && q != NULL && p->data == q->data ) { p = p->next; q = q->next; } if ( p == NULL && q == NULL ) { printf("两串相等n"); } else { printf("两串不等n"); } }
求串长
int strlength(linkstrnode* s) { int i = 0; linkstrnode* p = s->next; while (p != NULL) { i++; p = p->next; } return i; }
串连接
linkstrnode* concat(linkstrnode* s, linkstrnode* t) { linkstrnode* str, * p = s->next, * q, * r; str = (linkstrnode*)malloc(sizeof(linkstrnode)); r = str; while (p != NULL) { q = (linkstrnode*)malloc(sizeof(linkstrnode)); q->data = p->data; r->next = q; r = q; p = p->next; } p = t->next; while (p!=NULL) { q = (linkstrnode*)malloc(sizeof(linkstrnode)); q->data = p->data; r->next = q; r = q; p = p->next; } r->next = NULL; return str; }
求子串
linkstrnode* substr(linkstrnode* s, int i, int j) { int k; linkstrnode* str, * p = s->next, * q, * r; str = (linkstrnode*)malloc(sizeof(linkstrnode)); str->next = NULL; r = str; if ( i <= 0 || i > strlength(s) || j < 0 || i + k - 1 > strlength(s)) { return str; } for ( k = 0; k < i - 1; k++) { p = p->next; } for ( k = 0; k <= j; k++) { q = (linkstrnode*)malloc(sizeof(linkstrnode)); q->data = p->data; r->next = q; r = q; p = p->next; } r->next = NULL; return str; }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算