串插入
来源:互联网 发布:软件测试培训 编辑:程序博客网 时间:2024/06/15 03:12
//链串中串插入运算#include <stdio.h>#include <stdlib.h>typedef struct snode{char data;struct snode *next;}LiString; //链串节点类型void StrAssingn(LiString **s, char str[]) //尾插法建立链串{LiString *p, *r;int i;*s = (LiString *)malloc(sizeof(LiString)); //建立链串头节点r = *s; //r 始终指向链串s 的尾节点for (i = 0; str[i] != '\0'; i++){p = (LiString *)malloc(sizeof(LiString));p->data = str[i];r->next = p; //最后一个节点后加上pr = p; //让p 指向最后一个节点}r->next = NULL;}void StrInsert(LiString *s, int i, LiString *t){ //将链串t 插入到链串s 的第i 个节点位置LiString *p, *r;int k;p = s->next;for (k = 0; k < i - 1; k++){p = p->next;}r = p->next; //第i 个阶段开始的串p->next = t->next;p = t; //p 指向链串t 的头节点while (p->next != NULL){p = p->next;}p->next = r; }int main(){LiString *head1, *head2, *p;char c1[20] = "ABCD", c2[10] = "abcd";StrAssingn(&head1, c1); //建立链串head1StrAssingn(&head2, c2); //建立链串head2StrInsert(head1, 2, head2); //将链串head2插入到链串head1 中p = head1->next;while (p != NULL){printf("%2c", p->data);p = p->next;}printf("\n");return 0;}
阅读全文
1 0
- 串插入
- 插入、
- 插入
- 插入
- 串指出位置的插入
- 字符串子串的插入
- python json串插入mysql
- fjnu 1736 串中插入子串
- [Ruby乐趣]批量插入文本串
- 插入最少字符成为回文串
- 1159 Palindrome(最少插入回文串)
- 字符串的删除,插入,取串
- 顺序串的实现(插入、截取、匹配)
- 链串的建立与插入操作
- 插入最少字符使原串变成回文串
- 【数据结构】算法4.4 串插入操作
- 插入排序--直接插入
- 插入排序--折半插入
- AVL树的python实现
- 【iOS】Cocoa(iOS,OSX)安保系统设计实现
- Java基础知识02-流程控制-do while
- 计算机网络复习笔记---第一章(计算机网络和因特网)
- 企业资深架构师,月薪几十万的技术大牛,总结的七条经验
- 串插入
- linux 进程调度切换过程分析
- 负载测试、压力测试和性能测试的异同
- 拓扑排序
- java开发环境安装配置
- 欢迎使用CSDN-markdown编辑器用法
- jquery easyui中datebox输入设置事件
- hdoj1041
- unity引擎基础