zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    iOS7 Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2903.2/UIView.m:8536
    mac上launchpad上顽固图标的删除办法
    证书和配置文件
    直接调用对象方法的两种方式
    Instrument使用
    ios第三方库和工具类
    pod 私有 pod 库创建和使用
    iOS 新 app 上架准备
    iOS 上架记录:Other
    ios Permission denied Command PhaseScriptExecution failed with a nonzero exit code
  • 原文地址:https://www.cnblogs.com/askDing/p/5978401.html
Copyright © 2011-2022 走看看