List - } } index --; } public boolean isEmpty() { if(index...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
package lab9; p public class List { p final int MAX_SIZE = 100; private Object [] list; private int index; private int pos; p public List() { list = new Object[MAX_SIZE]; index = 0; pos = 0; } public List(int newSize) { list = new Object[newSize]; index = 0; pos = 0; } public int getLength() { return list.length; } public void insert(Object anObj) { list[index] = anObj; index++; } public void insert(Object anObj, int i) { list[i] = anObj; } public int getIndex() { return index; } public int isThere(Object anObj) { boolean flag = false; int found = -1; for(int i = 0; i<index & flag == false; i++) { if(list[i].equals(anObj)) { flag = true; found = i; } else { flag = false;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} } return found; } public void delete(Object anObj) { int found = this.isThere(anObj); if(found > -1) { for(int i = found; i < index; i++) { list[i] = list[i+1];
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } index --; } public boolean isEmpty() { if(index == 0) return true; else return false; } public boolean isFull() { if(index == list.length) return true; else return false; } public void reset() { pos = 0; } public Object getNext() { if(pos == index-1) this.reset(); return list[pos]; } public void selectionSort() { int min = 0; Object tempComboLock = new ComboLock(); for(int i=0; i&lt;index-1; i++) { min = i; for(int j = i+1; j&lt;index; j++) { if(((ComboLock)(list[j])).getId()&lt;((ComboLock) (list[min])).getId()) { min = j; } } tempComboLock = list[min]; list[min] = list[i]; list[i] = tempComboLock; l } } public void display() { for(int i= 0; i&lt;index; i++) { System.out.println(list[i].toString()); } } }...
View Full Document

This note was uploaded on 09/10/2009 for the course CS 102 taught by Professor Kanipiakins during the Spring '09 term at University of Maryland Baltimore.

Page1 / 3

List - } } index --; } public boolean isEmpty() { if(index...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online