using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表_增删改插_逆至_最小值
{
class MysEqList
{
public int _flag;
private int[] _ints;
public MysEqList()
{
_flag = 0;
_ints = new int[30];
}
public MysEqList(int _count)
{
_flag = 0;
_ints = new int[_count];
}
public void AddItem(int Item) //增加
{
if (_flag >= _ints.Length)
{
Console.WriteLine("溢出..");
return;
}
_ints[_flag] = Item;
_flag++;
}
public int RemoveAt(int index) //按照指定索引下标删除
{
int returnValue = default(int);
if (index < 0 || index >= _flag)
{
Console.WriteLine("超出范围...");
goto returnTip;
}
returnValue = _ints[index];
for (int i = index; i < _flag - 1; i++)
{
_ints[i] = _ints[i - 1];
}
_flag--;
returnTip:
return returnValue;
}
public void Remove(int removeItem) //按照指定元素进行删除
{
int tmpIndex = -1;
for (int i = 0; i < _flag; i++)
{
if (_ints[i].Equals(removeItem))
{
tmpIndex = i;
break;
}
}
if (tmpIndex != -1)
{
RemoveAt(tmpIndex);
}
}
public int indexOf(int Item) //查找元素,返回对应下标
{
int returnValue = -1;
for (int i = 0; i < _flag; i++)
{
if (_ints[i].Equals(Item))
{
returnValue = i;
break;
}
}
return returnValue;
}
public void Insert(int index, int Item) //在指定位置插入元素
{
if (_flag >= _ints.Length)
{
Console.WriteLine("溢出..");
return;
}
if (index < 0 || index > _flag)
{
Console.WriteLine("索引出界..");
return;
}
for (int i = _flag; i > index; i--)
{
_ints[i] = _ints[i - 1];
}
_ints[index] = Item;
_flag++;
}
public void Reverse() //顺序表反转
{
int tmpItem = default(int);
for (int i = 0; i < _flag/2; i++)
{
tmpItem =_ints[i];
_ints[i] = _ints[_flag - i - 1];
_ints[_flag - i - 1] = tmpItem;
}
}
public int DeleteMin() //删除最小值
{
int tmpMin = _ints[0];
for (int i = 1; i < _flag; i++)
{
if (tmpMin > _ints[i])
{
tmpMin = _ints[i];
}
}
return tmpMin;
}
public int fun(int index)
{
return _ints[index];
}
}
class Program
{
static void Main(string[] args)
{
MysEqList num = new MysEqList();
num.AddItem(1);
num.AddItem(2);
num.AddItem(3);
num.AddItem(110);
num.AddItem(4);
num.AddItem(7);
num.AddItem(9);
for (int i = 0; i < num._flag; i++)
{
Console.WriteLine(num.fun(i));
}
Console.WriteLine("反转为========================");
num.Reverse(); //反转
for (int i = 0; i < num._flag; i++)
{
Console.WriteLine(num.fun(i));
}
Console.WriteLine("最小值为=========");
Console.WriteLine(num.DeleteMin());
Console.ReadLine();
}
}
}
输出结果: