线性表的顺序存储结构C语言版

#include <stdio.h>

#define MAXSIZE 101
#define N 10 typedef struct SeqList
{
int data[MAXSIZE];
int length;
}SeqList; void initList(SeqList *L);
int Listinsert(SeqList *L, int index, int e);
int Listdelete(SeqList *L, int index, int *e);
void printList(SeqList L); int main(void)
{
SeqList L;
int e;
initList(&L);
for (int i = 1; i <N; ++i)
{
Listinsert(&L,i,i);
}
printList(L);
printf("\n======\n");
for(int i=L.length;i>=1;--i)
{
Listdelete(&L,i,&e);
printf("%d\t", e);
}
putchar(10); return 0;
} void initList(SeqList *L)
{
L->length = 0;
} int Listinsert(SeqList *L, int index, int e)
{
if(L->length== MAXSIZE) return -1;
if(index<=L->length+1 && index>=1)
{
if(index==L->length+1)
{
L->data[L->length+1] = e;
L->length += 1;
}
else
{
for (int i = L->length; i >= index ; --i)
{
L->data[i+1] = L->data[i];
}
L->data[index] = e;
L->length += 1;
} return 0;
}
return -1; } int Listdelete(SeqList *L, int index, int *e)
{
if(index>L->length) return -1;
*e = L->data[index];
for(int i=index;i<=L->length;i++)
{
L->data[i] = L->data[i+1];
}
L->length -= 1;
return 0;
}
void printList(SeqList L)
{
for (int i = 1; i <= L.length; ++i)
{
printf("%d\t", L.data[i]);
}
}
上一篇:2017.2.7 开涛shiro教程-第六章-Realm及相关对象(一)


下一篇:RandomAccessFile、FileChannel、MappedByteBuffer读写文件