|
发表于 2021-10-24 18:28:40
|
显示全部楼层
- #include <stdio.h>
- #define MaxSize 100
- typedef int ElemType;
- typedef struct
- {
- ElemType data[MaxSize];
- int length;
- }SeqList;
- int ListInit(SeqList *L)
- {
- L->length = 0;
- return L->length;
- }
- int ListInesrt(SeqList *L, int i, ElemType x)
- {
- int j;
- if (L->length == MaxSize)
- {
-
- printf("程序已满无法插入!\n");
- return 0;
- }
- else if (i < 1 || i > L->length + 1)
- {
- printf("插入位序不合法\n");
- return 0;
- }
- else
- {
- L->data[i-1] = x;
- L->length++;
- return 1;
- }
- }
- int ListDelete(SeqList* L, int i ,ElemType* x)
- {
- int j;
- if (L->length == 0)
- {
- printf("顺序表已无数据可删!\n");
- return 0;
- }
- else if ( i<1 || i > L->length)
- {
- printf("删除位序不合法");
- return 0;
- }
- else
- {
- *x = L->data[i-1];
- L->length = i - 1;
- return 1;
- }
- }
- int ListGet(SeqList *L, int i, ElemType* x)
- {
- if (i < 1 || i > L->length)
- {
- printf("获取位置不合法!\n");
- return 0;
- }
- else
- {
- *x = L->data[i-1];
- return 1;
- }
- }
- void main() //main
- {
- SeqList mylist;
-
- int i, x;
-
- ListInit(&mylist);
-
- for (i = 1; i <= 10; i++)
- ListInesrt(&mylist, i, i);
-
- ListDelete(&mylist, 4, &x);
-
- for (i = 1; i <= mylist.length ; i++)
- {
- ListGet(&mylist, i, &x);
- printf("%d ", x);
- }
- }
复制代码
你这个delete和insert的具体需求是什么呢 |
|