#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e4;
typedef struct SqList
{
int data[MAX_N];
int length;
} SqList;
void deleteX(SqList &L, int x)
{
int k = 0;
for (int i = 0; i < L.length; i++)
{
if (L.data[i] != x)
{
L.data[k] = L.data[i];
++k;
}
}
L.length = k;
}
int main()
{
SqList L;
L.data[0] = 1;
L.data[1] = 2;
L.data[2] = 3;
L.data[3] = 3;
L.data[4] = 7;
L.data[5] = 8;
L.data[6] = 10;
L.length = 7;
cout << "begin: ";
for (int i = 0; i < L.length; i++)
{
cout << L.data[i] << " ";
}
deleteX(L, 3);
cout << "\nafter: ";
for (int i = 0; i < L.length; i++)
{
cout << L.data[i] << " ";
}
return 0;
}
线性表删除指定元素
最新推荐文章于 2024-03-29 23:38:19 发布