文本编辑修正版(Text editor revision).docVIP

  • 4
  • 0
  • 约1.77万字
  • 约 39页
  • 2017-07-29 发布于河南
  • 举报
文本编辑修正版(Text editor revision)

文本编辑修正版(Text editor revision) # includes stdio.h # includes malloc.h # includes conio.h # includes stdlib.h # define success 1 / / 定义操作成功的标志为success # define failure 0 / / 定义操作失败的标志为failure typedef struct _ string / / 定义链串结构 { char character; / / 组成串的字符 (数据域) struct _ string * next; / / 指向下一串结构的指针 (链域) } / / 串类型 string; typedef struct _ stringinformation / / 定义串信息结构 { string * str; / / 链串首结点 int letters _ count; / / 字母个数 int figures _ count; / / 数字个数 int space _ count; / / 空格个数 int characters _ count; / / 总字符个数 stringinformation}; / / 串信息类型 typedef struct _ index / / 定义串索引结构 { int (_ index; / / 子串在其父串的位置 (或索引) struct _ index * next _ index; / / 指向子串的下一个串索引结构的指针 } / / 串索引类型 index; int stringlength (string * s) / / 求串长 { int length = 0; while (s! = = null) / / (s = = null) 即表示为s 为空串 { length + +; d = s - next; } return length; } void stringcopy (string * * targetstring, string * sourcestring) / / 串拷贝 { string * newnode, * tailnode; if (sourcestring = = null) * targetstring = null; / / 空串则直接赋值为null else / / 非空串则需另开辟内存空间 { * targetstring = (string *) malloc (sizeof (string)); / / 建立串首结点 (* targetstring) - character = sourcestring - character; tailnode = * targetstring; sourcestring = sourcestring - next; / / 源串移至其第二个字符 while (sourcestring! = = null) { newnode = (string *) malloc (sizeof (string)); / / 新建结点 newnode - character = sourcestring - character; / / 子字符复制 tailnode - next = newnode; / / 新建结点插入到尾结点后 tailnode = newnode; / / 新建结点成为尾结点 sourcestring = sourcestring - next; / / 继续复制源串的下一个字符 } tailnode - next = null; / / 尾结点的链域为空 (null) } } int stringcompare (string * s1, string * s2) / / 字符串比较, 相等返回0 { while (s1. = null s2. = = null) if (s1 - s2 - character character) return 1; 其他的 如果(字符字符) 返回- 1; 其他的 如果(S1 -字符= = S2 -字符)/若相等则继续比较下一字符 { 下一个; 下一个; } 如果(S1)!= null S2 = = null)/父串比子串大,返回1 返回1; 其他的 如果(= =!= null) 返回- 1; 返回0; } CreatStringFromArray(空字符串的**字符串CString)/通过字符数组建立串 { 字符串节点,* tailnode; 如果(* = =“0”字符串) * S = null;/ /字符数组为空串时,则* = null 其他的 { *

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档