66-70.数据结构复习
来源:互联网 发布:跑跑卡丁车淘宝刷车队 编辑:程序博客网 时间:2024/06/04 18:15
#include"stdio.h" #include"malloc.h" #define MaxSize 50 typedef struct{ char data[MaxSize]; int length; }SqList; void InitList(SqList *&L) { L=(SqList *)malloc(sizeof(SqList)); L->length=0; } void DispList(SqList *L) { int i; for(i=0;i<L->length;i++) printf("%c",L->data[i]); printf("\n"); } int ListLength(SqList *L) { return(L->length); } bool ListEmpty(SqList *L) { return(L->length==0); } bool getelem(SqList *L,int i) { if(i<1||i>L->length) return false; else { printf("%c",L->data[i]); return true; } } int LocateElem(SqList *L,char m) { int i=0; while(i<L->length&&L->data[i]!=m) i++; if(i>=L->length) return 0; else return i+1; } bool ListInsert(SqList *&L,int i,char m) { int j; if(i<1||i>L->length+1) return false; i--; for(j=L->length;j>i;j--) L->data[j]=L->data[j-1]; L->data[i]=m; L->length++; return true; } bool ListDelete(SqList *&L,int i) { int j; if(i<1||i>L->length) return false; i--; for(j=i;j<L->length-1;j++) L->data[j]=L->data[j+1]; L->length--; return true; } void DestroyList(SqList *&L) { free(L); } void main() { SqList *A; InitList(A); ListInsert(A,1,'a'); ListInsert(A,2,'b'); ListInsert(A,3,'c'); ListInsert(A,4,'d'); ListInsert(A,5,'e'); DispList(A); ListLength(A); ListEmpty(A); getelem(A,3); LocateElem(A,97); ListInsert(A,4,102); DispList(A); ListDelete(A,3); DispList(A); DestroyList(A); }
实现顺序表的各种功能
阅读全文
0 0
- 66-70.数据结构复习
- 复习'''数据结构'
- 复习数据结构
- 数据结构复习
- 数据结构复习
- 数据结构复习
- 数据结构复习
- 数据结构复习
- 数据结构复习
- 数据结构复习
- 数据结构复习-递归复习
- 【NOIp复习】数据结构复习列表
- 【数据结构】复习笔记
- [数据结构复习]字符串1
- 数据结构复习指南
- 数据结构复习指南2
- 数据结构复习篇:栈
- 数据结构复习篇:栈
- ubuntu/windoes下串口调试、telnet、ssh工具
- CNN中权值共享理解
- Leetcode 7 Reverse Integer
- Java中的内部类01-什么是内部类
- pycharm 解决No Python interpreter selected的问题
- 66-70.数据结构复习
- 使用自定义控件的正确姿势
- Leetcode 9 Palindrome Number 回文数
- MySQL 定时器EVENT学习
- ubuntu16.04如何同时安装python2和python3
- LeetCode 26 Remove Duplicates from Sorted Array
- PHP之生成左填充0的编号(存储到MYSQL)
- 标准C/C+头文件
- LeetCode 167 Two Sum 2-Input array is sorted