Docsity

ADT Sorted List - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

Download ADT Sorted List - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Chapter 4

ADT Sorted List

  • Lecture

Brainstorming

• A group problem-solving technique that

involves the spontaneous contribution of ideas

from all members of the group

• All ideas are potential good ideas

• Think fast and furiously first, and ponder later

• A little humor can be a powerful force

• Brainstorming is designed to produce a list of

candidate classes

Brainstorming

• Step 1 : review brainstorming principles at the beginning

of the meeting

  • remind everyone that this is a group activity and personal style

should be put aside.

• Step 2 : state specific session objectives

  • such as: “Today we want to come up with a list of candidate

classes for the sorted ADT or grocery store checkout system .”

• Step 3 : use a round-robin technique to allow the group

to proceed at an even tempo but give people enough

time to think.

  • Each person should contribute a possible object class to the list.
  • A facilitator should keep the discussion on target, and a scribe

should take notes.

Scenarios

• a sequence of steps that describes an

interaction between a client/user and an

application/program

• Simulate class interactions

• to Assign responsibilities to each class

• Ask “What if?” questions

• There are two types of responsibilities

• What a class must know about itself

( knowledge)

• What a class must be able to do ( behavior) 7

Responsibility Algorithms

• The algorithms must be written for the

responsibilities

• Knowledge responsibilities usually just

return the contents of one of an object’s

variables

• Action responsibilities are a little more

complicated, often involving calculations

Computer Example

• First pass at a list of

classes

Computer Example

• Filtered list

Responsibility Algorithms

Object-oriented vs. Top Down

• Object-oriented design

• focuses on the data objects that are to be

transformed

• resulting in a hierarchy of objects

• nouns are the primary focus

• nouns in objects; verbs become operations

• Top-down design

• focus on the process of transforming the input

into the output,

• resulting in a hierarchy of tasks

• verbs are the primary focus Docsity.com 14

Member functions

Which member function specifications

and implementations must change to

ensure that any instance of the Sorted

List ADT remains sorted at all times?

• PutItem

• DeleteItem

InsertItem algorithm for SortedList ADT

• Find proper location for the new

element in the sorted list.

• Create space for the new element by

moving down all the list elements that

will follow it.

• Put the new element in the list.

• Increment length.

void SortedType :: PutItem ( ItemType item )

{ bool moreToSearch; int location = 0; // find proper location for new element moreToSearch = ( location < length ); while ( moreToSearch ) { switch ( item.ComparedTo( info[location] ) ) { case LESS : moreToSearch = false; break; case GREATER : location++; moreToSearch = ( location < length ); break; } } // 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

• Find the location of the element to

be deleted from the sorted list.

• Eliminate space occupied by the

item by moving up all the list

elements that follow it.

• Decrement length.