3.1 Using Arrays
모든 배열은 일단 null로 되어있다
삽입기능 - 숫자를 추가하는데 모음이 꽉찼으면 작은수보다 더 크고 큰수보다 더 작은 곳에 넣어야한다 null이면 넣는다
Code
public void add(GameEntry e)
{
int newScore = e.getScore();
// is the new entry e really a high score
if(newEntries == maxEntries)
{
if(newScore <= entries[numEntries-1].getScore())
return;
}
else
numEntries++;
int i = numEntries-1;
for(; (i>=1) && (newScore > entries[i-1].getScore()); i--)
entries[i] = entries[i-1]
entries[i] = e;
}
제거기능 - 지우고 나서 지운것 다음 정렬도 해야됨
Code
public GameEntry remove(int i ) throws IndexOutOfBoundsException
{
if ((i<0) || (i >= numEntries))
throw new IndexOutOfBoundsException("Invalid index :" + i);
GameEntry temp = entries[i];
for(int j = i; j <numEntries - 1; j++)
entries[j] = entries[j+1];
entries[numEntries - 1] = null;
numEntries--;
return temp;
}
정렬기능
3.2 Singly Linked Lists
'일상 > Data Structure' 카테고리의 다른 글
2.Object-oriented Design (0) | 2017.03.26 |
---|