Top rank per group: Difference between revisions
Content added Content deleted
Line 113: | Line 113: | ||
=={{header|Aime}}== |
=={{header|Aime}}== |
||
<lang aime>void |
<lang aime>void |
||
Add_Employee(record employees, text name, |
Add_Employee(record employees, text name, id, integer salary, text department) |
||
⚫ | |||
{ |
{ |
||
employees[name] = list(name, id, salary, department); |
employees[name] = list(name, id, salary, department); |
||
Line 120: | Line 119: | ||
void |
void |
||
collect(record top, |
collect(record top, employees) |
||
{ |
{ |
||
list l |
for (, list l in employees) { |
||
top.v_index(l[3]).v_list(l[2]).link(-1, l); |
|||
⚫ | |||
for (text department, index x in top) { |
|||
⚫ | |||
x.ucall(l_ucall, 0, l_append, 1, t); |
|||
for (, l in employees) { |
|||
if (N < ~t.reverse) { |
|||
t.erase(N, -1); |
|||
department = r_v_list(top, l[3]); |
|||
salary = l[2]; |
|||
⚫ | |||
while (i < ~department) { |
|||
if (__list(department[i])[2] < salary) { |
|||
break; |
|||
} |
|||
i += 1; |
|||
⚫ | |||
l_l_list(department, i, l); |
|||
⚫ | |||
department.delete(N); |
|||
} |
} |
||
⚫ | |||
} |
} |
||
} |
} |
||
void |
void |
||
print_department(text department, list employees) |
|||
print(record top) |
|||
{ |
{ |
||
o_("Department ", department, "\n"); |
|||
list employees; |
|||
for ( |
for (, list l in employees) { |
||
o_form(" ~ | ~ | ~\n", l[0], l[1], l[2]); |
|||
o_("Department ", department, "\n"); |
|||
for (, l in employees) { |
|||
o_form(" ~ | ~ | ~\n", l[0], l[1], l[2]); |
|||
} |
|||
} |
} |
||
} |
} |
||
Line 185: | Line 166: | ||
collect(top, employees); |
collect(top, employees); |
||
top.wcall(print_department, 0, 1); |
|||
0; |
|||
}</lang>Run as: |
}</lang>Run as: |
||
<pre>aime rcs/top_rank_per_group c N 5</pre>{{out}} |
<pre>aime rcs/top_rank_per_group c N 5</pre>{{out}} |