using System;
using System.Collections.Generic;
using System.Text;
/*问题描述:
* 已知顺序表La,
* 构造Lb,
* 要求Lb中只包含顺序表La中所有不相同的值
* Purge:使洁净, 使净化, 清洗, 清除, 使(机构)变得廉洁起来
*/
namespace UniqueItem
{
class Program
{
static void Main(string[] args)
{
List<int> left = new List<int>();
Random rd = new Random();
Console.WriteLine("生成数据:");
for (int i = 0; i < 10; i++)
{
int temp = rd.Next(0, 4);
left.Add(temp);
Console.Write(temp + " ");
}
Console.WriteLine("/n/n/n");
List<int> result = Purge(left);
foreach (int node in result)
{
Console.Write(node + " ");
}
Console.WriteLine();
Console.ReadLine();
}
public static List<int> Purge(List<int> left)
{
if (left.Count == 0)
{
return null;
}
List<int> result = new List<int>();
result.Add(left[0]);
for (int i = 1; i < left.Count; i++)
{
for (int j = 0; j < result.Count; j++)
{
if (left[i] == result[j])
{
goto NoSame;
}
}
result.Add(left[i]);
NoSame: ;
}
return result;
}
}
}