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 ...
随机推荐
- google closure--继承模块一:goog.inherits()
最近在项目是使用了google closure框架,深入研究了一下源码,先从最简单的继承系统吧. 废话不多说,closure继承模块主要有2个API: goog.inherits(childCtor, ...
- 【转】图像灰度化方法总结及其VC实现
转载自: http://blog.csdn.net/likezhaobin/article/details/6915754 最近一段时间作者开始进行运动目标识别定位系统设计,本文以及后续的几篇文章都 ...
- 扩展django的User的部分方法
这做项目时发现django自带的User中的字段不够用,默认的auth_user表总共只有11个字段,如果需要更多的字段该怎么办,在网上搜了一下,有这么几种方法. 1. 直接修改django 源码,修 ...
- AudioUnit 用法
1.描述音频单元 AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentS ...
- 悲惨记忆。。QImage之 pixel() && setPixel()参数不要给反了。。。
QImage repairImg(width, height, QImage::Format_Mono); ; row < height; row++) { // uchar* ucRow = ...
- python sqlite 插入的数据含有变量,结果不一致
def insert(): conn = sqlite3.connect("sqlite.db") print "open database passed" t ...
- Appium学习笔记(一)--安装与配置
移动自动化测试常用工具有两个:Appium和Robotium.正好最近自己开始负责客户端的工作,初来乍到需要熟悉下环境,正好学习新的东西. 移动自动化相对web来说,原理与操作过程是一样的,通过自动化 ...
- 深入浅出REST
不知你是否意识到,围绕着什么才是实现异构的应用到应用通信的“正确”方式,一场争论正进行的如火如荼:虽然当前主流的方式明显地集中在基于SOAP.WSDL和WS-*规范的Web Services领域,但也 ...
- 什么是 kNN 算法?
学习 machine learning 的最低要求是什么? 我发觉要求可以很低,甚至初中程度已经可以. 首先要学习一点 Python 编程,譬如这两本小孩子用的书:[1][2]便可. 数学方面 ...
- MySQL - MySQL++在c++11环境下接口设计
安装官方提供的mysqlconnect后,可以使用mysql++库,在官方的C API上再次做一个c++面向对象封装. 这里mysql++的安装依赖于mysql-connector-c.安装参考:ht ...