数据结构——c语言描述 第四章 字符串
来源:互联网 发布:北京it系统集成商 编辑:程序博客网 时间:2024/05/16 11:16
今天心情不好,状态十分差,昨晚没睡好,进早上还早起,就写一点吧,这章是很简单的。上个代码。
#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAXSIZE 20#define FALSE 0#define TRUE 1typedef struct String { char string[MAXSIZE]; int length;}SString;int InitStr (SString **S , char *c) { char *ptr = c; *S = (SString *) malloc (sizeof (SString)); (*S)->length = 0; while (*ptr != '\0') { (*S)->string[(*S)->length] = *ptr; (*S)->length++; ptr++; }}int StrInsert (SString *a , int pos , SString *b) { int i; if (pos <= 0 || pos >= MAXSIZE || pos > a->length) return FALSE; if (a->length + b->length <= MAXSIZE) { for (i = 0 ; i < a->length - pos + 1 ; i++) { a->string[a->length-i-1+b->length] = a->string[a->length-i-1]; } for (i = 0 ; i < b->length ; i++) a->string[pos-1+i] = b->string[i]; a->length += b->length; }else if (pos + b->length <= MAXSIZE) { for (i = 0 ; i < MAXSIZE - pos - b->length + 1 ; i++) a->string[a->length-1+i+b->length] = a->string[a->length-1-i]; for (i = 0 ; i < b->length ; i++) a->string[pos-1+i] = b->string[i]; a->length = MAXSIZE; }else { for (i = 0 ; i < MAXSIZE - pos + 1 ; i++) a->string[pos-1+i] = b->string[i]; a->length = MAXSIZE; } return TRUE;}
地一个函数是初始化,第二个是插入函数,分三种情况讨论。
0 0
- 数据结构——c语言描述 第四章 字符串
- 数据结构(C语言描述)—排序
- 《数据结构与算法分析(c 描述)》—— 第四章笔记
- 数据结构(C语言描述)
- C语言描述数据结构———封装DLL
- 数据结构与算法(C语言描述)——单链表
- 数据结构C 语言描述——实现栈的基本功能
- 数据结构与算法分析——C语言描述3.3
- 数据结构—单链表(类C语言描述)
- 《数据结构和算法分析—C语言描述》读书笔记
- 《数据结构与算法分析—C语言描述》pdf
- 数据结构——C语言描述 第二章(1) 顺序表
- 数据结构——c语言描述 第二章(2) 单向链表
- 数据结构——c语言描述 第二章(3) 双向链表
- 数据结构——c语言描述 第三章(3) 队列
- 数据结构——c语言描述 第五章 (1) 特殊矩阵的压缩存储
- 数据结构——c语言描述 第五章 (2) 稀疏矩阵的转置算法
- 数据结构——c语言描述 第五章(3)十字链表存储稀疏矩阵
- 提高项目12.5-数组大折腾
- ACM总结体会
- Android中的自定义注解
- hibernate_Restrictions用法 hibernate_Restrictions用法
- 更新BLE的设备后,OSX LightBlue 不会更新扫描到Service
- 数据结构——c语言描述 第四章 字符串
- 用可视化修改layer层
- Which machine learning algorithms can be considered as among the best?
- [leetcode] 369. Plus One Linked List 解题报告
- 第二天 变量,常量,数据类型和运算符
- Qt 录音程序
- 非maven项目部署web项目报错,ClassNotFoundException
- window下Flask项目的创建
- 默写网站