Computer >> 컴퓨터 >  >> 프로그램 작성 >> 프로그램 작성

데이터 구조의 ADT 배열 표현

<시간/>

기본 개념

ADT는 추상 데이터 유형을 나타냅니다.

배열은 동일한 순서로 연속 요소를 보유할 수 있기 때문에 ADT로 정의됩니다. 그리고 그들은 허용

인덱스 또는 위치를 통해 특정 요소에 대한 액세스.

String, int 또는 Person이 될 수 있기 때문에 추상입니다.

int[] arrA = new int[1];
String[] arrB = new String[1];
Person[] arrC = new Person[3]; // where Person is treated as a defined class

장점

  • 항목 또는 요소에 대한 빠르고 임의 액세스
  • 메모리 효율성이 매우 높고 콘텐츠를 저장하는 데 필요한 메모리 외에는 거의 필요하지 않습니다.

단점

  • 느린 요소 삽입 및 삭제
  • 배열이 생성되고 고정(정적)될 때 배열 크기를 알아야 합니다.

ADT 목록의 어레이 기반 구현

Public class ListArrayBased implementsListInterface {
   private static final int MAX_LIST1 = 50;
   private Object items1[];
   // an array of list items
   privateint numItems1;
   // number of items in list
   publicListArrayBased() {
      items1 = new Object[MAX_LIST1];
      numItems1 = 0;
   } // end default constructor
}