Data Structure(with C).Experiment01.01
来源:互联网 发布:java线程池编程实例 编辑:程序博客网 时间:2024/05/22 13:19
============algo2-1.cpp============
#include<stdio.h>#include<stdlib.h>#define MaxSize 6typedef struct{char data[MaxSize];int length;}SqList;void InitList(SqList *&L){L=(SqList *)malloc(sizeof(SqList));L->length=0;}void DestroyList(SqList *&L){free(L);}bool ListEmpty(SqList *&L){return (L->length==0);}int ListLength(SqList *&L){return (L->length);}void DispList(SqList *&L){int i=0;for(i;i<L->length;i++)printf("%c ",L->data[i]);printf("\n");}bool GetChar(SqList *&L,int i,char &e){if(i<1||i>L->length)return false;e=L->data[i-1];return true;}int LocateChar(SqList *&L,char e){int i=0;while(i<L->length&&L->data[i]!=e)i++;if(i>=L->length)return 0;elsereturn i+1;}bool ListInsert(SqList *&L,int i,char e){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]=e;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 ListTialIns(SqList *&L,char e){L->data[L->length]=e;L->length++;}
==========exp2-1============
#include "algo2-1.cpp"void main(){SqList *L;char e;InitList(L);ListTialIns(L,'a');ListTialIns(L,'b');ListTialIns(L,'c');ListTialIns(L,'d');ListTialIns(L,'e');DispList(L);printf("The list-length is:%d\n",ListLength(L));if(ListEmpty(L))printf("The list is empty!\n");elseprintf("The list is not empty!\n");if(GetChar(L,3,e))printf("The third element of the list is:%c\n",e);elseprintf("The element is not found!\n");printf("The element a's location is:%d\n",LocateChar(L,'a'));ListInsert(L,4,'f');DispList(L);ListDelete(L,3);DispList(L);DestroyList(L);}
- Data Structure(with C).Experiment01.01
- Data Structure(with C).Experiment01.02
- C Linked List Data Structure Explained with an Example C Program
- Data Structure
- Data structure
- Data Structure
- Data structure
- Data structure
- data structure
- Data Structure
- Data structure
- Data Structure
- Data Structure
- Data Structure
- Data Structure
- Data Structure for HTML DOM with compare text inside
- Data structure alignmentData structure alignment
- LeetCode-Add and Search Word - Data structure design(C++)
- OCP-1Z0-053-V12.02-117题
- android studio报错:Could not execute build using Gradle installation
- 侯捷推荐书籍(转载)
- 从零开始学习Hadoop--补一 一个实际的例子
- 在Linux上安装Memcached服务
- Data Structure(with C).Experiment01.01
- 解决php与mysql交互 中文乱码
- 开发时上传资源共享,基于windows下软件开发
- 侯捷推荐书籍(续二)
- 排列组合
- 关于需求分析的几点体会
- 如何正确的重写equals方法(避免各种陷阱)
- 输入、汇编、连接、执行、调试过程
- 侯捷推荐书籍(续一)