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后的成员是属于类的,是不属于任何对象实例,其他类是无法访问的,只对类的实例共享,能一定程序对该成员尽心 ...
随机推荐
- DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版原创发布-带官方示例程序版
关于 DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版------------- ...
- 学习git config配置文件
设置 git status的颜色. git config --global color.status auto 一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一 ...
- SQLSERVER排查CPU占用高的情况
SQLSERVER排查CPU占用高的情况 今天中午,有朋友叫我帮他看一下数据库,操作系统是Windows2008R2 ,数据库是SQL2008R2 64位 64G内存,16核CPU 硬件配置还是比较高 ...
- 对“Git”认知。
并没有接触过这个名词,相信在今后的学习和生活中会接触.不过在网上大致看了一下,应该是一种类似于后台控制的系统吧,希望以后自己会了解这个陌生的东西(软件?系统?程序?).
- VIM C++语法高亮配色
因工作需求,必须在终端下远程下代码,vim打开cpp/h文件,看到一连串的字母就傻了,根本无法阅读. 后来才知道VIM这高大上的文本编辑器支持很多的功能,很多的功能.首先最基本的就是语法高亮配色 1. ...
- BZOJ 1537 二维偏序
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- 实时控制软件设计 第一次作业 Draw
#include <iostream> #include <cstring> #include <math.h> #include <Eigen/Dense& ...
- Android 开发常用命令
1.生成keystore文件 keytool -exportcert -keystore keystore_path -list -v 2.查看APK签名 keytool -list -printce ...
- mongodb C# 驱动查询
INoSqlProvider provider = NoSqlManager.Create("CloudTable"); IMongoCollection<FormMongo ...
- day04关于MySqL—Android小白的学习笔记
Mysql入门 1. 数据库基本知识(了解) 1.1.数据库介绍 1.1.1.什么是数据库?数据库的作用是什么? 数据库就是存储数据的仓库,其本质是一个文件系统,数据按照特定的格式将数据存储起来,用户 ...