标签:style blog color io os ar for sp div
#include<iostream> #include<sctring> #include<string> #include<cstdlib> #define maxsize 100 using 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; } }
标签:style blog color io os ar for sp div
原文地址:http://www.cnblogs.com/tong1487/p/4013964.html