Sequential List
Sequential List
Sequential list storage structure:
#define LIST_INIT_SIZE 20
#define LIST_INCREASE 10
typedef int Elemtype;
typedef struct
{
ElemType data; /* an array to store data */
int length; /* current length of list */
int listSize; /*max list size*/
}SqList;
Operations:
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef int Status;
/* Status is defined as the type of function. Its value will
be the status code of the function such as OK. */
/*dynamically initialize a list*/
Status InitList(SqList *L)
{
/*let L->data point to newly allocate memory*/
L->data=(int *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
/*allocation failure*/
if(!L->data)
{
return ERROR;
}
L->length=0;
L->listSize=LIST_INIT_SIZE;
return OK;
}
int ListLength(SqList *L)
{
return (L->length);
}
/* retrieve value of number i data element in list L to e */
Status GetElem(SqList L, int i, ElemType *e)
{
/*list empty or illegal i*/
if(L.length==0||i<1||i>L.length)
{
return ERROR;
}
*e = L.data[i-1];
return OK;
}
/* find which index has the data we are looking for.*/
int LocateElem(SqList *L, char *key)
{
int i;
ElemType *e;
for(i=0;i>=L->length;i++)
{
GetElem(L,i,e)
if(strcmp(*e==key)
{
return i;
}
}
return ERROR;
}
Status ListExpand(SqList *L)
{
ElemType *base;
base=(ElemType*)realloc(L->data,(L->listSize+LIST_INCREASE)*sizeof(ElemType));
if(base)
{
return ERROR;
}
L->data=base;
L->listSize=L->listSize+LIST_INCREASE;
return OK;
}
/*insert an element e before i in list L,
increase list length by 1.*/
Status ListInsert(SqList *L, int i, ElemType e)
{
int k;
/*i is illegal*/
if(i<1||i>L->length+1)
{
return ERROR;
}
/*if space not enough*/
if(L->length>=L->listSize)
{
ListExpand(*L);
}
/*i is not at the end of list.*/
if(i<=L->length)
{
/*move all elements after i backwards
for 1 position*/
for(k=L->length-1;k>=i-1;k--)
{
L->data[k+1]=L->data[k];
}
}
/*insert the new element*/
L->data[i-1]=e;
/*increase the list length by 1.*/
L->length++;
return OK;
}
/*append new element at the end.*/
Status ListAppend(SqList *L,ElemType e)
{
if(L->length>=L->listSize)
{
ListExpand(*L);
}
L->data[++L->length]=e;
return OK;
}
/*delete the number 1 element from list L and
return its value with e,decrease
the length of list L by 1.*/
Status ListDelete(SqList *L,int i,ElemType *e)
{
int k;
if(L->length==0) /*list empty*/
{
return ERROR;
}
if(i<1||L->length) /*illegal i*/
{
return ERROR;
}
/*return the value to element to be deleted*/
*e=L->data[i-1];
if(i<L->length) /*element is not the end*/
{
/*move every element after i
forward by 1 position*/
for(k=i;k<L->length;k++)
{
L->data[k-1]=L->data[k];
}
}
/*decrease the length of L by 1.*/
L->length--;
return OK;
}
Sequential List的更多相关文章
- Creating a SharePoint Sequential Workflow
https://msdn.microsoft.com/en-us/library/office/hh824675(v=office.14).aspx Creating a SharePoint Seq ...
- Support Vector Machine (2) : Sequential Minimal Optimization
目录 Support Vector Machine (1) : 简单SVM原理 Support Vector Machine (2) : Sequential Minimal Optimization ...
- completed solution matches microsoft sequential workflow tutorial
microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...
- Time Series data 与 sequential data 的区别
It is important to note the distinction between time series and sequential data. In both cases, the ...
- Java中的查找算法之顺序查找(Sequential Search)
Java中的查找算法之顺序查找(Sequential Search) 神话丿小王子的博客主页 a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数 ...
- Loadrunner中参数化实战(1)-Sequential+Each iteration
参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:
- Sequential Read Ahead For SQL Server
Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...
- control file sequential read 等待事件
可能的原因 control file sequential read Reading from the control file. This happens in many cases. For ex ...
- sequential minimal optimization,SMO for SVM, (MATLAB code)
function model = SMOforSVM(X, y, C ) %sequential minimal optimization,SMO tol = 0.001; maxIters = 30 ...
随机推荐
- hihoCoder#1014
刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正. 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小 ...
- [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys
错误原因在于出现相同内容. 原写为: <li ng-repeat="log in logs" scroll-down> {{log}}</li> 改写为: ...
- centos 7 下安装numpy、scipy等python包
本文适用于刚入门的小白,欢迎大牛们批评指正. 因为要开始数据分析,而python又不像R和matlab那么简洁.需要安装的包很多~ 网上找了好多牛人博客,想在centos7下安装numpy,scipy ...
- java语言程序设计(一)-1
java 语言的特点是: 强类型,制定了比较多的语言规范,尽可能在编译阶段检测出更多的错误及警告. 编译和解释,首先将源代码编译成codebyte,运行时,java的运行系统装载和链接需要执行的类,并 ...
- 《java异常的一些总结》
关于Java中异常的一些总结: 3 有些时候,程序在try块里打开了一些物理资源(例如数据库连接,网络连接. 4 和磁盘文件等),这些物理资源都必须显示回收. 5 6 注意:Java的垃圾回收机制不会 ...
- 一款公用的CSS+DIV弹窗
为了方便以后自己使用! <html> <head> <style> .winmainshow { background: #fff; padding: 10px 5 ...
- github的使用步骤及体会
对于github的readme文件的提交,很是坎坷. 首先打开了github的首页,对于满屏的英文,我是头大的.百度搜索教程,百度翻译等等,这些都使用上了.带着试一试的态度,我按了creat ...
- C语言程序设计第二次作业
一.学习内容 掌握关系运算符.逻辑运算符.条件运算符 掌握常用数学函数的用法 if语句(单分支,双分支和多分支) 用switch语句实现多分支 理解多个if语句,if...else if... 和if ...
- 用tcpdump分析tcp三次握手,四次挥手
1.tcpdump 简介 tcpdump是一个对网络上的数据包进行截获的包分析工具,一般linux系统以命令的形式使用 2.tcp三次握手 建立一个tcp连接会发生下面三个过程: 1.服务器必须准备好 ...
- navicat在ubuntu下中文乱码的真正解决方法ZT
乱码解决方法(自己解决我自己这种情况之后打猜测): 打开start_navicat文件,会看到 export LANG="en_US.UTF-8" 将这句话改为 export LA ...