#include<stdio.h>
#include<string.h>
#include<math.h>
typedef int ElemType;
#define MaxSize 60
typedef struct {
ElemType data[MaxSize];
int length;
}Sqlist;
void Creatlist_Sq(Sqlist*&L,ElemType a[], int n)
{
int i;
L = (Sqlist*)malloc(sizeof(Sqlist));
for (i = 0; i < n; i++)
L->data[i] = a[i];
L->length = n;
}
void Initlist_Sq(Sqlist*& L)
{
L = (Sqlist*)malloc(sizeof(Sqlist));
L->length = 0;
}
bool ListInsert_Sq(Sqlist * &L, int i, ELemType e)
{
int j;
if (i<1 || i>L->length + 1)
return FALSE;
i--;
for (j = L->length; j > i; j--)
L->data[j] = L->data[i];
L->data[i - 1] = e;
L->length++;
return TRUE;
}
void ListTraverse_Sq(Sqlist*& L)
{
int i;
for (i = 0; i < L->length; i++)
printf("%d", L->data[i]);
printf("\n");
}
int ListLength_Sq(Sqlist*& L)
{
return (L->length);
}
bool ListEmpty_Sq(Sqlist* L)
{
return (L->length == 0);
}
void ListTravers_Sq(Sqlist*& L)
{
int i=2;
printf("%d", L->data[i]);
printf("\n");
}
bool ListDelete_Sq(Sqlist*& L, int i, ElemType& e)
{
int j;
if ((i < 1) || (i->lengt))
return FALSE;
i--;
e = L->data[i];
for (j = ilj < L->length - 1; j++)
L->data[j] = L->data[j + 1];
L->length--;
return TRUE;
}
void DestroyList_Sq(Sqlist*& L)
{
free(L);
}
//菜单
void menu()
{
printf("********1.初始化 2.插入*********\n");
printf("********3.输出L 4.输出长度*********\n");
printf("********5.判断是否为空 6.输出第三个***\n");
printf("********7.输出元素a的逻辑位置 8.插入*********\n");
printf("********9.清空 *********\n");
}
int main()
{
Sqlist L; int choice;
InitList(L);
while (1)
{
menu();
printf("请输入菜单序号:\n");
scanf("%d", &choice);
if (10 == choice) break;
switch (choice)
{
case 1:Initlist_Sq(L); break;
case 2:ListInsert_Sq(Sqlist * &L, int i, ELemType e); break;
case 3:ListTraverse_Sq(Sqlist * &L); break;
case 4:Initlist_Sq(Sqlist * &L); break;
case 5:ListEmpty_Sq(Sqlist * L); break;
case 6: ListTravers_Sq(Sqlist * &L); break;
/*case 7:PrintList(L); break;*/
case 8:ListInsert_Sq(Sqlist * &L, int i, ELemType e); break;
case 9:DestroyList_Sq(Sqlist * &L); break;
default:printf("输入错误!!!\n");
}
}
return 0;
}