#include<iostream>
#define MaxSize 50
using namespace std;
typedef int Elemtype;
typedef struct {
int data[MaxSize];
int length;
}SqList;
void InitList(SqList& L)
{
for (int i = 0; i < MaxSize; i++)
L.data[i] = 0;
L.length = 0;
}
void CreateList(SqList &L,int n)
{
for (int i = 0; i < n; i++)
{
cin >> L.data[i];
L.length++;
}
}
void ShowList(SqList& L)
{
for (int i = 0; i < L.length; i++)
cout << L.data[i] <<' ';
//cout << L.data[3];
cout << endl;
}
bool ListInsert(SqList& L, int i, int e)
{
if (i<1 || i>L.length + 1)
return false;
if (L.length >= MaxSize)
return false;
for (int j = L.length; j >= i; j--)
L.data[j] = L.data[j-1];
L.data[i - 1] = e;
L.length++;
return true;
}
bool DeleteList(SqList& L, int i)
{
if (i<1 || i>L.length + 1)
return false;
for (int j = i; j < L.length; j++)
L.data[j - 1] = L.data[j];
L.length--;
return true;
}
int main()
{
SqList L;
InitList(L);
int i,n,e;
cin >> n;
CreateList(L, n);
ShowList(L);
/*cin >> i >> e;
ListInsert(L, i, e);*/
cin >> i;
DeleteList(L, i);
ShowList(L);
return 0;
}
顺序表基本操作
最新推荐文章于 2024-08-21 18:53:45 发布