Upcoming SlideShare
×

# 강의자료7

404 views
313 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
404
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
1
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 강의자료7

1. 1. What is a List? <ul><li>A list is a homogeneous collection of elements, with a linear relationship between elements. </li></ul><ul><li>That is, each list element (except the first) has a unique predecessor, and each element (except the last) has a unique successor. </li></ul>
2. 2. ADT Unsorted List Operations <ul><li>Transformers </li></ul><ul><ul><li>MakeEmpty </li></ul></ul><ul><ul><li>InsertItem </li></ul></ul><ul><ul><li>DeleteItem </li></ul></ul><ul><li>Observers </li></ul><ul><ul><li>IsFull </li></ul></ul><ul><ul><li>LengthIs </li></ul></ul><ul><ul><li>RetrieveItem </li></ul></ul><ul><li>Iterators </li></ul><ul><ul><li>ResetList </li></ul></ul><ul><ul><li>GetNextItem </li></ul></ul>change state observe state process all
3. 3. <ul><li>// SPECIFICATION FILE ( unsorted.h ) </li></ul><ul><li>class UnsortedType // declares a class data type </li></ul><ul><li>{ </li></ul><ul><li>public : // 8 public member functions </li></ul><ul><li>…… </li></ul><ul><li> </li></ul><ul><li>private : // 3 private data members </li></ul><ul><li>// 리스트를 배열로 표현 </li></ul><ul><li>int length ; </li></ul><ul><li>ItemType info[MAX_ITEMS] ; // MAX_ITEMS 은 상수임 </li></ul><ul><li>int currentPos ; </li></ul><ul><li>// Linked List 구현 </li></ul><ul><li>private : </li></ul><ul><li>NodeType* listData; </li></ul><ul><li>int length; </li></ul><ul><li>NodeType* currentPos; </li></ul><ul><li>} ; </li></ul>ADT Unsorted List 의 Linked 리스트 구현 struct ItemType { … . KeyType key; … };
4. 4. class UnsortedType MakeEmpty ~UnsortedType DeleteItem . . . InsertItem UnsortedType RetrieveItem GetNextItem ‘ X’ ‘C’ ‘L’ Private data: length 3 listData currentPos ?
5. 5. Linked Implementation 다음 세 가지의 차이점 ? location , *location , 과 location->info
6. 6. <ul><li>s truct NodeType </li></ul><ul><li>{ </li></ul><ul><li>ItemType info; </li></ul><ul><li>NodeType* next; </li></ul><ul><li>}; </li></ul><ul><li>class UnsortedType </li></ul><ul><li>{ </li></ul><ul><li>public : // LINKED LIST IMPLEMENTATION </li></ul><ul><li>UnsortedType ( ) ; </li></ul><ul><li>~UnsortedType ( ) ; </li></ul><ul><li>void MakeEmpty ( ) ; </li></ul><ul><li>bool IsFull ( ) const ; </li></ul><ul><li>int LengthIs ( ) const ; </li></ul><ul><li>void RetrieveItem ( ItemType& item, bool& found ) ; </li></ul><ul><li>void InsertItem ( ItemType item ) ; </li></ul><ul><li>void DeleteItem ( ItemType item ) ; </li></ul><ul><li>void ResetList ( ); </li></ul><ul><li>void GetNextItem ( ItemType& item ) ; </li></ul><ul><li>private : </li></ul><ul><li>NodeType* listData; </li></ul><ul><li>int length; </li></ul><ul><li>NodeType* currentPos; </li></ul><ul><li>} ; </li></ul>
7. 7. <ul><li>// LINKED LIST IMPLEMENTATION ( unsorted.cpp ) </li></ul><ul><li>#include “itemtype.h” </li></ul><ul><li>template <class ItemType> </li></ul><ul><li>UnsortedType<ItemType>::UnsortedType ( ) // constructor </li></ul><ul><li>// Pre: None. </li></ul><ul><li>// Post: List is empty. </li></ul><ul><li>{ </li></ul><ul><li>length = 0 ; </li></ul><ul><li>listData = NULL; </li></ul><ul><li>} </li></ul><ul><li>template <class ItemType> </li></ul><ul><li>int UnsortedType<ItemType>::LengthIs ( ) const </li></ul><ul><li>// Post: Function value = number of items in the list. </li></ul><ul><li>{ </li></ul><ul><li>return length; </li></ul><ul><li>} </li></ul>