home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
WDESAMPL.BIN
/
EmployeeList.java
< prev
next >
Wrap
Text File
|
1997-08-23
|
2KB
|
84 lines
public class EmployeeList
{
LinkList fir = null;
LinkList cur = null;
public void add(Employee e)
{
if (cur == null) fir = new LinkList(e);
else fir = fir.cons(e);
cur = fir;
}
/**
* Sort the employee list on one of the three fields: name, section, or SS#
*/
public void sort(int fld)
{
// Use a bubble sort, for simplicity
LinkList e = fir;
while (e != null)
{
LinkList ee = e.rest();
while (ee != null)
{
switch (fld)
{
case Employee.NAME_FLD:
if
(
(((Employee)(e.value())).name).
isGreaterThan
((((Employee)(ee.value()))).name)
)
LinkList.swapValues(e, ee);
break;
case Employee.AGE_FLD:
if
(
(((Employee)(e.value())).section).
isGreaterThan
((((Employee)(ee.value()))).section)
)
LinkList.swapValues(e, ee);
break;
case Employee.SSN_FLD:
if
(
(((Employee)(e.value())).ssn).
isGreaterThan
((((Employee)(ee.value()))).ssn)
)
LinkList.swapValues(e, ee);
break;
}
ee = ee.rest();
}
e = e.rest();
}
}
/**
* Return the first employee in the list
*/
public Employee first()
{
cur = fir;
if (cur == null) return null; else return (Employee)(cur.value());
}
/**
* Return the next employee in the list
*/
public Employee next()
{
if (cur == null) return null; else cur = cur.rest();
if (cur == null) return null; else return (Employee)(cur.value());
}
}