/** * A class containing list of records with insert/delete * and search funcionality. * * @author Vivek Rane */ public class RecordDB { private static int maxRecords = 20; private int numRecords = 0; private Record recordList[] = new Record[maxRecords]; /** * Inserts a record into the ordered array in a sorted fashion. * @param rec - The record to be inserted. */ public void insert (Record rec) { // Check for overflow if (numRecords == maxRecords-1) { return; // Increase the size of the array maybe } // Find the position to insert in int i; for (i=0; i rec.ssn) break; } // Shift all records one space down for (int j=numRecords-1; j>=i; j--) { recordList[j+1] = recordList[j]; } // Insert the new record recordList[i] = rec; // Increment current number of employees in the list numRecords++; printAll(); } /** * Deletes a record from the list based on the key (ssn). * @param ssn */ public void delete (long ssn) { int i; for (i=0; i ssn) { System.out.println("Record not found: " + ssn); return; } // SSN found if (recordList[i].ssn == ssn) { break; } } for (int j=i; j ssn) { last = current-1; continue; } if (recordList[current].ssn < ssn) { first = current+1; continue; } } } /** * Prints the list of records to the standard output; */ private void printAll() { System.out.println("---------------------------"); for (int i=0; i