首页 > 代码库 > 静态链表

静态链表

#include<iostream>#include<sctring>#include<string>#include<cstdlib>#define maxsize 100using namespace std;typedef struct{    char data;    int next;//游标代替指针}staticlist[maxsize];//建立静态链表void creat(staticlist L,char a[],int n){    int i = 0;    L[0].next = 1;    for(i = 1;i <= n;i++)    {        strcpy(L[i].data,a[i-1]);        L[i].next = i+1;    }    L[n].next = 0;//将尾元素的指针域置为0,形成循环链表}//初始化void initlist(staticlist L){    int j;    L[0].next = 0;    for (j = 1;j < maxsize;j++)        L[j].next = -1;}//判断是否为空表int listEmpty(staticlist L){    return (L[0].next == 0);}int listlength(staticlist L){    int i = 0,j = 0;    while (L[j].next != 0)    {        i++;        j = L[j].next;//指向下一个游标    }    return i;}//输出void displist(staticlist L){    int j = 0;    while (L[j].next != 0)    {        j = L[j].next ;        cout << j << ": " << L[j].data << "游标值: " << L[j].next << endl;    }}

 

静态链表