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的更多相关文章

  1. Creating a SharePoint Sequential Workflow

    https://msdn.microsoft.com/en-us/library/office/hh824675(v=office.14).aspx Creating a SharePoint Seq ...

  2. Support Vector Machine (2) : Sequential Minimal Optimization

    目录 Support Vector Machine (1) : 简单SVM原理 Support Vector Machine (2) : Sequential Minimal Optimization ...

  3. completed solution matches microsoft sequential workflow tutorial

    microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...

  4. Time Series data 与 sequential data 的区别

    It is important to note the distinction between time series and sequential data. In both cases, the ...

  5. Java中的查找算法之顺序查找(Sequential Search)

    Java中的查找算法之顺序查找(Sequential Search) 神话丿小王子的博客主页 a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数 ...

  6. Loadrunner中参数化实战(1)-Sequential+Each iteration

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:

  7. Sequential Read Ahead For SQL Server

    Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...

  8. control file sequential read 等待事件

    可能的原因 control file sequential read Reading from the control file. This happens in many cases. For ex ...

  9. sequential minimal optimization,SMO for SVM, (MATLAB code)

    function model = SMOforSVM(X, y, C ) %sequential minimal optimization,SMO tol = 0.001; maxIters = 30 ...

随机推荐

  1. C++重载流运算符,将存储结构体的vector直接写入文件

    我们知道,当vector很大的时候,如果使用循环的方式将其中的元素写入文件将非常费时,因此有没有办法将vector一次性写入文件呢? 采用流运算符重载的方法可以做到,不仅基本类型的vector可以一次 ...

  2. IOS调用系统声音(键盘声音)

    #import <AudioToolbox/AudioToolbox.h> AudioServicesPlaySystemSound(1106); 注:括号中为系统声音的id,详见 htt ...

  3. break into Ubuntu System

    This morning, I got a spare machine from of of the labmates. The OS is ubuntu 12.04. I could not log ...

  4. Python开发入门与实战16-APACHE部署

    16. Windows平台apache部署 本章节我们简要的描述一下如何在windows平台部署apache的django站点. Python Django 项目部署发布到windows apache ...

  5. [转]iOS7中UITextView contentsize改变时机

    在iOS7以下版本中,对UITextView设置了text属性,则contentsize就会变化,从而可以根据contentsize的变化来改变UITextView高度来做出TextView高度随着输 ...

  6. 5-26课堂作业——组员投票Alpha版存在的问题

    我们在课上讨论了Alpha版目前发现的问题,并通过投票的方式,选出其中三个认为是当前须紧要解决的问题. 问题: 1.缺少数据库: 2.用户体验不良好,游戏难度分区不明显: 3.团队成员共同工作时间少.

  7. Java学习1 - java 历史

    Sun的Java语言开发小组成立于1991年,其目的是开拓消费类电子产品市场,例如:交互式电视,烤面包箱等.Sun内部人员把这个项目称为 Green,那时World Wide Web还在图纸上呢.该小 ...

  8. jsp九大内置对象和四大作用域

    看到网上一些Jsp内置对象介绍的都不是很全,今天我把各位大神的整理了一下. JSP九大对象:内置对象(又叫隐含对象,有9个内置对象):不需要预先声明就可以在脚本代码和表达式中随意使用. 一.reque ...

  9. 国内app快速生成平台对比

     泰格老虎 2013-03-07 00:39:10 这是海恒CEO高鹏写的一篇国内app快速生成平台对比文章,介绍了国内快速生成APP的平台与自己平台的对比,很有参考价值. 同类网站 安米网 http ...

  10. MSSQL数据库安装失败

    1停止所有跟Sql相关的服务:控制面板-〉管理工具-〉服务2.在控制面板中卸载所有和SQL有关的一切程序或者组建3.注册表清理():3.1彻底删除SQL Server: hkey_local_mach ...