lab1soln - directory[index-1] = directory[index]; }...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
1. private String getDirectory() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < numEntries; i++) sb.append(directory[i].getName() + " / " + directory[i].getNumber() + "\n"); return sb.toString(); } 2. private int find(String name) { for (int i = 0; i < numEntries; i++) { if (directory[i].getName().equals(name)) { return i; } } return -1; // Name not found } 3. public String removeEntry(String name) { int namePosition = find(name); if (namePosition > -1) { String oldNumber = directory[namePosition].getNumber(); for (int index = namePosition+1; index < numEntries; index++) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: directory[index-1] = directory[index]; } numEntries--; directory[numEntries] = null; modified = true; return oldNumber; } return null; // if name not found } 4. public String removeEntry(String name) { int namePosition = find(name); if (namePosition > -1) { String oldNumber = directory[namePosition].getNumber(); System.arraycopy(directory, namePosition+1, directory, namePosition, numEntries-(namePosition+1)); numEntries--; directory[numEntries] = null; modified = true; return oldNumber; } return null; // if name not found...
View Full Document

This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.

Ask a homework question - tutors are online