More than 20,000 employees by age ranking algorithm,
Algorithm thinking is the idea of choosing a sort algorithm, taking into account more than 20,000 employees, at a certain age when the value of a number of employees will have the actual situation.
Ideas
The first search to find, the minimum age of M minage, the maximum age of N MaxAge, so that the age of the range [Minage, MaxAge]; second, search step 1, all found, after the M minage, in turn ...
C # code implementation,
Personnel model for,
public class person
{public person
(int staffno, int age)
{
this.staffno = staffno;
This.age = age;
}
Work number public
int staffno {get;set;}
Age public
int age{get;set;}
}
Step to 1 sorting search algorithm:
static void sort ()
{
if (list = = null) return;
Find out who is the youngest of the list
list<person> minagepersons = getagepersons (list. Min (per => per.age));
Find out who is the oldest list
list<person> maxagepersons = getagepersons (list. Max (per => per.age));
Remove these values
list = list. Except (minagepersons). Except (maxagepersons). ToList ();
for (int age = minagepersons[0].age+1;age<maxagepersons[0].age;age++)
{
list<person> agepersons = Getagepersons (age);
Minagepersons.addrange (agepersons);
List. Except (agepersons);
}
Minagepersons.addrange (maxagepersons);
list = minagepersons;
}
static list<person> getagepersons (int age)
{return
List. FindAll (person => person.age = = age);
}
The age of the person does not necessarily step into 1, so improve the sort (),
static void sort ()
{
if (list = = null) return;
Find out who is the youngest of the list
list<person> minagepersons = getagepersons (list. Min (per => per.age));
List = list. Except (minagepersons). ToList ();
Do
{
list<person> tmpminagepersons = getagepersons (List. Min (per => per.age));
Minagepersons.addrange (tmpminagepersons);
List = list. Except (tmpminagepersons). ToList ();
} while (list. Count > 0);
list = minagepersons;
}
Source Address:
After downloading, list = list. Except (minagepersons). ToList () moves outside the Do loop. (a small problem that was found after uploading the code)
http://download.csdn.net/detail/daigualu/9782742