Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

In the subject of the Data Structures, the key concept and the main points, which are very important in the context of the data structures are listed below:Adt Unsorted List, Linear Relationship, List Definitions, Each Element, Unique Predecessor, Length, Unique Successor, Number of Items, Unsorted List, Sorted List

Typology: Slides

2012/2013

Uploaded on 04/23/2013

saratey
saratey 🇮🇳

4.3

(10)

87 documents

1 / 75

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 3
ADT Unsorted List
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b

Partial preview of the text

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

Chapter 3

ADT Unsorted List

  • Lecture

List Definitions

Unsorted list

A list in which data items are placed in no

particular order;

the only relationship between data elements is the

list predecessor and successor relationships.

Sorted list

A list that is sorted by the value in the key;

There is a semantic relationship among the

keys of the items in the list.

Key

The attributes that are used to determine the

logical order of the list. Docsity.com^4

Abstract Data Type (ADT)

• A data type whose properties

(domain and operations) are

specified independently of any

particular implementation.

ADT Operations

• Constructor

• Transformer

• Observer

• Iterator

Sorted and Unsorted Lists

UNSORTED LIST

Elements are placed

into the list in

no particular order.

SORTED LIST

List elements are in an

order that is sorted in

some way

  • either numerically,
  • alphabetically by the

elements themselves, or

by a component of the

element

  • called a KEY member

What is a Generic Data Type?

A generic data type is a type for which the

operations are defined

but the types of the items being manipulated

are not defined.

One way to simulate such a type for our

UnsortedList ADT is via

a user-defined class ItemType with

member function ComparedTo

returning an enumerated type value LESS,

GREATER, or EQUAL.

// SPECIFICATION FILE ( unsorted.h ) #include “ItemType.h”

class UnsortedType // declares a class data type { public : // 8 public member functions void UnsortedType ( ); bool IsFull ( ) const; int GetLength ( ) const ; // returns length of list ItemType GetItem ( ItemType item, bool& found); void PutItem ( ItemType item ); void DeleteItem ( ItemType item ); void ResetList ( ); ItemType GetNextItem ();

private : // 3 private data members int length; ItemType info[MAX_ITEMS]; int currentPos; };

Class Constructor Rules

1 A constructor cannot return a function value,

and has no return value type.

2 A class may have several constructors.

The compiler chooses the appropriate constructor by the

number and types of parameters used.

3 Constructor parameters are placed in a parameter list

in the declaration of the class object.

4 The parameterless constructor is the default

constructor.

5 If a class has at least one constructor, and an array of

class objects is declared, then one of the constructors

must be the default constructor, which is invoked for

each element in the array.

Class Interface Diagram

UnsortedType class

IsFull

GetLength

ResetList

DeleteItem

PutItem

UnsortedType

GetItem

GetNextItem

Private data:

length

info [ 0 ]

[ 1 ] [ 2 ]

[MAX_ITEMS-1]

currentPos

Before Inserting Henry into an

Unsorted List

length 3

info [ 0 ] Maxwell

[ 1 ] Bradley

[ 2 ] Asad

[ 3 ]

[MAX_ITEMS-1]

The item will

be placed into

the length location,

and length will be

incremented.

After Inserting Henry into an

Unsorted List

length 4

info [ 0 ] Maxwell

[ 1 ] Bradley

[ 2 ] Asad

[ 3 ] Henry

[MAX_ITEMS-1]

19

ItemType UnsortedType::GetItem ( ItemType item, bool& found ) // Pre: Key member of item is initialized. // Post: If found, items key matches an elements key in the list // and a copy of that element is returned; // otherwise, input item is returned. { bool moreToSearch; int location = 0;

found = false; moreToSearch = ( location < length ); while ( moreToSearch && !found ) { switch ( item.ComparedTo( info[location] ) ) { case LESS : case GREATER : location++; moreToSearch = ( location < length ); break; case EQUAL : found = true; item = info[ location ]; break; } } return item; } (^) Docsity.com 19

Getting Ivan from an Unsorted List

moreToSearch: true

found: false

location: 0

length 4

info [ 0 ] Maxwell

[ 1 ] Bradley

[ 2 ] Asad

[ 3 ] Henry

[MAX_ITEMS-1]