{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

topic08_ArrayBasedLists

topic08_ArrayBasedLists - An Array-Based List ADT CS 1037a...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: An Array-Based List ADT CS 1037a – Topic 8 The List ADT • A list is a linear structure • Each item except the first ( front , head ) has a unique predecessor • Each item except the last ( end , tail ) has a unique successor • First item has no predecessor, and last item has no successor • An item within a list is specified by its position in the list 8-2 Possible Operations on a List List Create an empty list isEmpty Determine whether the list is empty isFull Determine whether the list is full getLength Return number of items in the list insert Add an item to the list remove Remove a specified item from list retrieve Get the list item at a specified pos’n 8-3 Why Use a List ADT? • Often, we could just use an array • May wish to separate what a list does from its implementation ( abstraction ) • Allows for a variety of implementations: • Fixed versus arbitrary capacity • Array-based versus linked lists (later in course) • More natural to work with than an array: first position is location 1 in a list, but at index 0 in an array 8-4 UML Diagram for List ADT List-m_size: integer-m_container +isEmpty: boolean {query} +isFull: boolean {query} +getLength: integer {query} +insert +remove +replace +retrieve {query} +swap This diagram is based on the design decisions we’ve made so far; type of m_container , and parameters and types for insert , remove, replace and retrieve are not yet known; other attributes and functions may be added later 8-5 The List ADT • In an unordered list, relative position of the items is not important • Differences with an ordered List ADT : • Items maintained in sorted order • Insertions, deletions based on item value, rather than position • Must be able to compare items to determine where they belong in the list 8-6 List ADT Design Decisions • What kinds of items will be allowed in the list? • What’s the underlying list implementation? • What parameters and return types will the operations have? • How will we handle attempts to insert into a full list, or remove from an empty list? • How will we handle attempts to access an illegal list position? 8-7 List ADT Implementation 1 • We’ll store either simple types (int, char, etc) or pointers to simple types or to objects • Underlying structure is an array with a fixed maximum size • insert operation will return a boolean value: true if operation is successful, false otherwise 8-8 List ADT Implementation 1 • remove and retrieve will return the item at a specified position; precondition : the position must be one that currently exists in the list • replace will change the item stored at a specified position, and return the displaced item; precondition : the position must be one that currently exists in the list • swap will change positions of 2 items stored at 2 specified positions, precondition : the positions must currently exist in the list 8-9 List ADT Implementation 1 • Adding an item to a list will change, at most,...
View Full Document

{[ snackBarMessage ]}

Page1 / 40

topic08_ArrayBasedLists - An Array-Based List ADT CS 1037a...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online