Static List
Static List
Static List is the smart implementation of list data structure for those languages that have no pointer or similar function, such as Pascal, Basic. It uses an auxilary array to store the locations of data in the main array, which is known as cursor,the supplicant of pointer.
Static List data structure
#define LIST_INIT_SIZE 100
typedef struct
{
ElemType data;
int cur; /*cursor,mean no pointing if 0.*/
}Component,StaticLinkList[LIST_INIT_SIZE];
How static list is organized:
1.Index 0 is reserved and stores no data.
2.Cursor 0 points to first empty index.
3.Last Cursor points to index first data element.
4.Each cursor points to index of its next element.
Operations:
/*space[0].cur is head pointer,
"0" indicates null pointer.*/
Status InitList(StaticLinkList space)
{
int i;
for(i=0;i<LIST_INIT_SIZE-1;i++)
{
space[i].cur=i+1;
}
/*current static linked list is empty,
cur of last element is 0.*/
space[LIST_INIT_SIZE-1].cur=0;
return OK;
}
/*return the cur of allocated node if the linked list is not
empty, otherwise return 0.*/
int AllocSLL(StaticLinkList space)
{
int i=space[0].cur;
if(space[0].cur)
{
space[0].cur=space[i].cur;
}
return i;
}
/*insert a new element e before i element.*/
Status ListInsert(StaticLinkList L,int i,ElemType e)
{
int j,k,l;
/*k set as cur of last element.*/
k=LIST_INIT_SIZE-1;
if(i<1||i>ListLength(L)+1)
{
return ERROR;
}
/*obtain cur of the allocated node.*/
j=AllocSSL(L);
if(j)
{
L[j].data=e;
for(l=1;l<=i-1;l++)
{
L[j].cur=L[k].cur;
}
L[k].cur=j;
return OK;
}
return ERROR;
}
void Free_SSL(StaticLinkList space,int k)
{
space[k].cur=space[0].cur;
space[0].cur=k;
}
Status ListDelete(StaticLinkList L,int i)
{
int j,k;
if(i<1||i>ListLength(L))
{
return ERROR;
}
k=MAXSIZE-1;
for(j=1;j<=i-1;j++)
{
k=L[k].cur;
}
j=L[k].cur;
L[k].cur=L[j].cur;
Free_SSL(L,j);
return OK;
}
int ListLength(StaticLinkList L)
{
int j=0;
int i=L[MAXSIZE-1].cur;
while(i)
{
i=L[i].cur;
j++;
}
return j;
}
Static List的更多相关文章
- static,你还敢用吗?(二)
为了压系统,昨天小组在测试环境模拟了一大批订单数据.今天上午查看记录的账单计息日志,发现了一大堆的MySqlException MySql.Data.MySqlClient.MySqlExceptio ...
- const,static,extern 简介
const,static,extern 简介 一.const与宏的区别: const简介:之前常用的字符串常量,一般是抽成宏,但是苹果不推荐我们抽成宏,推荐我们使用const常量. 执行时刻:宏是预编 ...
- const extern static 终极指南
const extern static 终极指南 不管是从事哪种语言的开发工作,const extern static 这三个关键字的用法和原理都是我们必须明白的.本文将对此做出非常详细的讲解. co ...
- PHP static静态属性和静态方法
这里分析了php面向对象中static静态属性和静态方法的调用.关于它们的调用(能不能调用,怎么样调用),需要弄明白了他们在内存中存放位置,这样就非常容易理解了.静态属性.方法(包括静态与非静态)在内 ...
- static,你还敢用吗?
我用火狐的HttpRequester测试开发组里一个同学发布的Web API接口,遇到了一个奇怪的问题. 我测试边界情况时,第一次调用响应的结果是正常的,但当再次及以后的请求时,却返回了异常“Syst ...
- Java关键字:static
通常,当创建类时,就是在描述那个类的外观和行为.只有用new创建类的对象时,才分配数据存储空间,方法才能被调用.但往往我们会有下面两种需求: 1.我想要这样一个存储空间:不管创建多少对象,无论是不创建 ...
- Android 中关于static的使用问题
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/5251564.html 项目中,在不停地接收串口数据很长一段时间(几小时)后,会偶然性的报错.初步排除了oom ...
- iOS: 在UIViewController 中添加Static UITableView
如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...
- 浅谈Static关键字
1.使用static关键字声明的属性为全局属性 未使用static关键字指定city之前,如果需要将Tom,Jack,Mary三人的城市均改成Beijing,需要再次声明三次对象的city为Beiji ...
- 今天思考一个问题,PHP const和static的区别
static关键字在类中是,描述一个成员是静态的,static能够限制外部的访问,因为static后的成员是属于类的,是不属于任何对象实例,其他类是无法访问的,只对类的实例共享,能一定程序对该成员尽心 ...
随机推荐
- C#文件流读写文件的简单winform实现
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- #HTML:無序、有序與定義清單
#HTML:無序.有序與定義清單 Maplewing 于 星期六, 12/10/2013 - 09:48 提交 清單在網頁中是很常使用到的東西,故多少還是要了解一下.在HTML中有三種不太一樣的清單, ...
- PreparedStatement
PreparedStatement > 它是Statement接口的子接口: >强大之处: 防SQL攻击: 提高代码的可读性.可维护性: 提高效率! l 学习PreparedStateme ...
- hosts持续更新
Google hosts网址: https://laod.cn/hosts/2016-google-hosts.html
- 软件测试第四周--关于int.parse()的类型转换问题
先来归纳一下我们用过的所有类型转换方法: 1. 隐式类型转换,即使用(int) 直接进行强制类型转换.这种方法的优点是简单粗暴,直接指定转换类型,没有任何保护措施,所以也很容易抛出异常导致程序崩溃.当 ...
- python3下载远程代码并执行
第一步: 先在gist之类的网站上贴上代码,目的不是高亮,而可以raw的形式获取代码,这样可以省掉处理html的时间,我这里用的是pasteraw: 远程上的代码:http://cdn.pastera ...
- MVC 请求处理流程(一)
路由系统先获取路由数据,在实现了IHttpModule接口的UrlRoutingModule对象中通过注册HttpApplication的PostResolveRequestCache来解析路由数据并 ...
- 安装生物信息学软件-HUMAnN2
先挖坑 因为这个软件需要memory>16G,所以应该要安装在服务器上
- Ubuntu 14.10下搭建简易FTP服务器[vsftpd]
Ubuntu下公认最易上手的ftp软件是vsftpd,既然标题都说了是“简易”的,那么必然是用最大众的..下面是正题 目标需求:搭建一个允许匿名/本地登录的FTP,并且支持上传/下载/修改功能,同时F ...
- Linux系统性能分析
http://c.biancheng.net/cpp/html/2782.htmlLinux系统性能分析 这篇教程的目的是向大家介绍一些免费的系统性能分析工具(命令),使用这些工具可以监控系统资源使用 ...