SlideShare une entreprise Scribd logo
1  sur  33
ADT Sorted List ( 정렬 리스트 )
List Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
List Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
List Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract Data Type (ADT)   ,[object Object]
ADT Sorted List Operations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],change state observe state process all
ADT 와  C++  클래스 ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],struct ItemType { … . KeyType key; … };
Class Interface Diagram SortedType class IsFull LengthIs  ResetList DeleteItem InsertItem SortedType RetrieveItem GetNextItem Private data: length info  [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1] currentPos
[object Object],[object Object],[object Object],[object Object],구현  ( IMPLEMENTATION )
배열 구현  ,[object Object],[object Object],[object Object],[object Object],currentPos length info  [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1]
Sorted Type Class Interface Diagram SortedType class IsFull LengthIs  ResetList DeleteItem InsertItem MakeEmpty RetrieveItem Private data: length info  [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1] currentPos GetNextItem
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],멤버 함수 구현
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Member functions   ,[object Object],[object Object],[object Object]
InsertItem algorithm forSortedList ADT ,[object Object],[object Object],[object Object],[object Object]
Implementing SortedType  me mber function    InsertItem // IMPLEMENTATION FILE  (sorted.cpp) #include “itemtype.h”  // also must appear in client code void  SortedType :: InsertItem ( ItemType  item ) //  Pre: List has been initialized. List is not full.  //  item is not in list. //  List is sorted by key member using function ComparedTo. // Post:  item is in the list.  List is still sorted. { . . . }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],I nsertItem
InsertItem void  SortedType :: InsertItem ( ItemType  item ) { int  location = 0 ; // find proper location for new element while ( location < length  ) { if (item.key < info[location].key) break; else location++;  } //  make room for new element in sorted list for  ( int  index = length ;  index  >  location ;  index-- )   info [ index ] = info [ index - 1 ] ; info [ location ] = item ; length++ ; }
DeleteItem algorithm for   SortedList ADT ,[object Object],[object Object],[object Object]
Delete Item ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Retrieve Item
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Improving member function   RetrieveItem ,[object Object],[object Object]
Binary Sea r ch  ( 이진탐색 )  in a Sorted List ,[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Retrieve Item
void  SortedType::RetrieveItem (  Item Type&  item,  bool&  found )  //  Pre: Key member of item is initialized. //  Post: If found, item’s key matches an element’s key in the list //   and a copy of that element has been stored in item; otherwise, item is unchanged. {  int  midPoint ; int  first  =  0; int   last  = length - 1 ; found = false ; while (  first <= last   &&  !found ) { midPoint  =  ( first + last ) / 2 ; // INDEX OF MIDDLE ELEMENT if (item.key < info[midPoint].key) last = midPoint – 1; else  if (item.key > info[midPoint].key) first = midPoint + 1; else  { found = true; item = info[midPoint]; } } }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Order of Magnitude of a Function ,[object Object],[object Object],[object Object],[object Object]
Names of Orders of Magnitude ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Big-O Comparison of List Operations ,[object Object],OPERATION   UnsortedList  SortedList RetrieveItem  O(N)   O(N)  linear search   O(log 2 N)  binary search InsertItem Find   O(1)   O(N)  search Put  O(1)   O(N)  moving down Combined  O(1)   O(N)  DeleteItem Find  O(N)   O(N)  search Put  O(1) swap   O(N)  moving up Combined  O(N)   O(N)
Object-Oriented Design ,[object Object],[object Object],[object Object]
Object-Oriented Design ,[object Object],[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Tendances (10)

Java collections-interview-questions
Java collections-interview-questionsJava collections-interview-questions
Java collections-interview-questions
 
Java2
Java2Java2
Java2
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
 
Java collection
Java collectionJava collection
Java collection
 
Generics
GenericsGenerics
Generics
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
 
Xxxx
XxxxXxxx
Xxxx
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Function Java Vector class
Function Java Vector classFunction Java Vector class
Function Java Vector class
 

En vedette

Newsbubble
NewsbubbleNewsbubble
Newsbubblepindec
 
Inseptra company product solutions v2 1
Inseptra company product solutions v2 1Inseptra company product solutions v2 1
Inseptra company product solutions v2 1Mustafa Kuğu
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15Syed Asrarali
 
Catálogo Cerruti
Catálogo CerrutiCatálogo Cerruti
Catálogo CerrutiCoartegift
 
Crm success with offshore outsourcing
Crm success with offshore outsourcingCrm success with offshore outsourcing
Crm success with offshore outsourcingCRM Vision
 
總體經濟指標
總體經濟指標總體經濟指標
總體經濟指標twnewone1
 
2能源技術服務業
2能源技術服務業2能源技術服務業
2能源技術服務業twnewone1
 
Issue71 cash-flows
Issue71 cash-flowsIssue71 cash-flows
Issue71 cash-flowsBsgr Planmin
 
GH and V-Tech
GH and V-TechGH and V-Tech
GH and V-TechGolin
 
Pedagog föreläsning i Ljusdal 15 april 2011
Pedagog föreläsning i Ljusdal 15 april 2011Pedagog föreläsning i Ljusdal 15 april 2011
Pedagog föreläsning i Ljusdal 15 april 2011Verbala Stigar
 
TSA's annual report recommendations 2011
TSA's annual report recommendations 2011TSA's annual report recommendations 2011
TSA's annual report recommendations 2011C-21
 
2011 GolinHarris Al's Day
2011 GolinHarris Al's Day2011 GolinHarris Al's Day
2011 GolinHarris Al's DayGolin
 
Alternative CV 2
Alternative CV 2Alternative CV 2
Alternative CV 2Gorkem Unel
 

En vedette (20)

Newsbubble
NewsbubbleNewsbubble
Newsbubble
 
Inseptra company product solutions v2 1
Inseptra company product solutions v2 1Inseptra company product solutions v2 1
Inseptra company product solutions v2 1
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15
 
Catálogo Cerruti
Catálogo CerrutiCatálogo Cerruti
Catálogo Cerruti
 
Crm success with offshore outsourcing
Crm success with offshore outsourcingCrm success with offshore outsourcing
Crm success with offshore outsourcing
 
Communication
CommunicationCommunication
Communication
 
總體經濟指標
總體經濟指標總體經濟指標
總體經濟指標
 
2011. informe 1º trimestre
2011. informe  1º trimestre2011. informe  1º trimestre
2011. informe 1º trimestre
 
2能源技術服務業
2能源技術服務業2能源技術服務業
2能源技術服務業
 
Issue71 cash-flows
Issue71 cash-flowsIssue71 cash-flows
Issue71 cash-flows
 
GH and V-Tech
GH and V-TechGH and V-Tech
GH and V-Tech
 
Saving japan
Saving japanSaving japan
Saving japan
 
Memory0607
Memory0607Memory0607
Memory0607
 
Pedagog föreläsning i Ljusdal 15 april 2011
Pedagog föreläsning i Ljusdal 15 april 2011Pedagog föreläsning i Ljusdal 15 april 2011
Pedagog föreläsning i Ljusdal 15 april 2011
 
Seattlefinal
SeattlefinalSeattlefinal
Seattlefinal
 
TSA's annual report recommendations 2011
TSA's annual report recommendations 2011TSA's annual report recommendations 2011
TSA's annual report recommendations 2011
 
2011 GolinHarris Al's Day
2011 GolinHarris Al's Day2011 GolinHarris Al's Day
2011 GolinHarris Al's Day
 
Earthquake
EarthquakeEarthquake
Earthquake
 
Codigos AC Nocturna 2015
Codigos AC Nocturna 2015Codigos AC Nocturna 2015
Codigos AC Nocturna 2015
 
Alternative CV 2
Alternative CV 2Alternative CV 2
Alternative CV 2
 

Similaire à 강의자료9

BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
c++Write a program to test the selection sort algorithm for array-.pdf
c++Write a program to test the selection sort algorithm for array-.pdfc++Write a program to test the selection sort algorithm for array-.pdf
c++Write a program to test the selection sort algorithm for array-.pdfakpatra2000
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdfarshin9
 
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdfssuserc77a341
 
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfJAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfsuresh640714
 
import java.util.ArrayList; import java.util.List;public class S.pdf
import java.util.ArrayList; import java.util.List;public class S.pdfimport java.util.ArrayList; import java.util.List;public class S.pdf
import java.util.ArrayList; import java.util.List;public class S.pdfanupamele
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...davidwarner122
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
Given the class specification of Unsorted Type as below- class Unsorte.docx
Given the class specification of Unsorted Type as below- class Unsorte.docxGiven the class specification of Unsorted Type as below- class Unsorte.docx
Given the class specification of Unsorted Type as below- class Unsorte.docxfrancescaj1
 

Similaire à 강의자료9 (20)

강의자료7
강의자료7강의자료7
강의자료7
 
Unsorted Sorted List_Array.pptx
Unsorted Sorted List_Array.pptxUnsorted Sorted List_Array.pptx
Unsorted Sorted List_Array.pptx
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
강의자료10
강의자료10강의자료10
강의자료10
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Chapter14
Chapter14Chapter14
Chapter14
 
Linked list1
Linked list1Linked list1
Linked list1
 
c++Write a program to test the selection sort algorithm for array-.pdf
c++Write a program to test the selection sort algorithm for array-.pdfc++Write a program to test the selection sort algorithm for array-.pdf
c++Write a program to test the selection sort algorithm for array-.pdf
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf(Unordered Sets) As explained in this chapter, a set is a collection.pdf
(Unordered Sets) As explained in this chapter, a set is a collection.pdf
 
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdfJAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
JAVA helpNeed bolded lines fixed for it to compile. Thank you!pu.pdf
 
import java.util.ArrayList; import java.util.List;public class S.pdf
import java.util.ArrayList; import java.util.List;public class S.pdfimport java.util.ArrayList; import java.util.List;public class S.pdf
import java.util.ArrayList; import java.util.List;public class S.pdf
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
Ds notes
Ds notesDs notes
Ds notes
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
Groovy
GroovyGroovy
Groovy
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
Given the class specification of Unsorted Type as below- class Unsorte.docx
Given the class specification of Unsorted Type as below- class Unsorte.docxGiven the class specification of Unsorted Type as below- class Unsorte.docx
Given the class specification of Unsorted Type as below- class Unsorte.docx
 

Plus de Young Wook Kim

Plus de Young Wook Kim (6)

강의자료8
강의자료8강의자료8
강의자료8
 
C review
C  reviewC  review
C review
 
강의자료4
강의자료4강의자료4
강의자료4
 
강의자료3
강의자료3강의자료3
강의자료3
 
강의자료 2
강의자료 2강의자료 2
강의자료 2
 
강의자료5
강의자료5강의자료5
강의자료5
 

강의자료9

  • 1. ADT Sorted List ( 정렬 리스트 )
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Class Interface Diagram SortedType class IsFull LengthIs ResetList DeleteItem InsertItem SortedType RetrieveItem GetNextItem Private data: length info [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1] currentPos
  • 10.
  • 11.
  • 12. Sorted Type Class Interface Diagram SortedType class IsFull LengthIs ResetList DeleteItem InsertItem MakeEmpty RetrieveItem Private data: length info [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1] currentPos GetNextItem
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. Implementing SortedType me mber function InsertItem // IMPLEMENTATION FILE (sorted.cpp) #include “itemtype.h” // also must appear in client code void SortedType :: InsertItem ( ItemType item ) // Pre: List has been initialized. List is not full. // item is not in list. // List is sorted by key member using function ComparedTo. // Post: item is in the list. List is still sorted. { . . . }
  • 18.
  • 19. InsertItem void SortedType :: InsertItem ( ItemType item ) { int location = 0 ; // find proper location for new element while ( location < length ) { if (item.key < info[location].key) break; else location++; } // make room for new element in sorted list for ( int index = length ; index > location ; index-- ) info [ index ] = info [ index - 1 ] ; info [ location ] = item ; length++ ; }
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. void SortedType::RetrieveItem ( Item Type& item, bool& found ) // Pre: Key member of item is initialized. // Post: If found, item’s key matches an element’s key in the list // and a copy of that element has been stored in item; otherwise, item is unchanged. { int midPoint ; int first = 0; int last = length - 1 ; found = false ; while ( first <= last && !found ) { midPoint = ( first + last ) / 2 ; // INDEX OF MIDDLE ELEMENT if (item.key < info[midPoint].key) last = midPoint – 1; else if (item.key > info[midPoint].key) first = midPoint + 1; else { found = true; item = info[midPoint]; } } }
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.

Notes de l'éditeur

  1. switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } ound
  2. switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } ound
  3. switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } ound
  4. switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } ound
  5. switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++ ; moreToSearch = ( location &lt; length ) ; case EQUAL : found = true ; item = info[ location ] ; break ; } ound