JD의 블로그

3. ADT(Abstract Data Type) 본문

-프로그래밍 언어/알고리즘&자료구조

3. ADT(Abstract Data Type)

GDong 2019. 9. 18. 02:49

1. What is ADT

Data type

1) Representation of data (How you are storing the data)

2) operations on data (What are the operations that you allow on the data)

 

Abstract

: hiding internal details.  (we need not know internal details - how these operations are performed.)

Without knowing them, we can use them. 

 

When the Object Oriented Programming languages being started to use in Software Development, then using the classes, we can define our own data types, that are Abstract.

 

 

2. List ADT

 

the data that is required for storing lise is, first I needspacefor storing elements. 

The second thins is, I need to have some capacity of a list. 

The third is, inside that capacity, how many elements already I have in the list, that is length of the list, or size of a list. (the number of it is having)

 

for representation of this one, I have two options. 

1) Array

2) Linked list 

 

Operations on a list

1) add(element), append(element) : I want to add something to the end of a list

  + add(index, element), insert(index, element) : adding an element at a given index (If you want to insert any element at a given index, then you have to shift the elements.)

2) remove(index) : After removing, we have to shift the rest of the elements.

3) Set(index, element), replace(index, element) : changing an element at a given index.

4) get(index) : I want to know the element at a given index

5) Search(key), contains(key) : searching for an element to find its index if it is present in the list.  

6) Sort() : to arrange all elements in some order

...

 

Having the representation of data + the operations = DataType

 

the concept of ADT , define the data, and operations on data together

and let it be used as data type, by hiding all the internal details!

 

when any class in C++ which has the data representation and operations together, it defines an ADT.