L04_lsq - COMP152 Spring 2010 D.Y. Yeung ADTs: Lists,...

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

View Full Document Right Arrow Icon
ADTs: Lists, Stacks and Queues Nyhoff: 6-8,11 COMP152 Spring 2010 D.Y. Yeung
Background image of page 1

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

View Full DocumentRight Arrow Icon
Outline COMP152 2 Lists An array-based implementation of lists Linked lists with pointer implementation Stacks Operations and implementations Applications: decimal to binary conversion, parenthesis matching, infix to postfix conversion, postfix computation, expression tree, etc. Queues Operations and implementations Bin-sort and radix sort
Background image of page 2
Lists in Daily Life COMP152 3 Shopping list Job to-do list List of assignments for a course Dean's list Can you name some others?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Properties of Lists COMP152 4 Can have a single element Can have no elements Can be lists of lists We will look at the list as an abstract data type (ADT) Homogeneous Finite length Sequential elements
Background image of page 4
Basic Operations COMP152 5 Construct an empty list Determine whether or not the list is empty Insert an element into the list Delete an element from the list Traverse (iterate through) the list to Modify Output Search for a specific element Copy or save Rearrange
Background image of page 5

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

View Full DocumentRight Arrow Icon
Designing a List Class COMP152 6 Should contain at least the following function members Constructor empty(): whether or not the list is empty insert(): insert an element into the list delete(): delete an element from the list display(): display all elements in the list Implementation involves Defining data members Defining function members from design phase
Background image of page 6
Array-Based Implementation of Lists COMP152 7 An array is a viable choice for storing list elements Elements are sequential It is a commonly available data type Algorithm development is easy Normally sequential ordering of list elements matches with that of array elements a[0] a[1] a[2] a[n-1] a[n] a[CAPACITY-1] Array: List: a 1 , a 2 , a 3 , , a n
Background image of page 7

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

View Full DocumentRight Arrow Icon
Implementing Operations COMP152 8 Constructor Static array allocated at compile time Empty Check if size == 0 Traverse Use a loop from the 0 th element to size – 1
Background image of page 8
Implementing Operations COMP152 9 Insert Shift elements to right of insertion point Delete Shift elements back Also adjust size up or down 23 25 34 48 61 79 82 89 91 99 ? ? 23 25 34 48 56 61 79 82 89 91 99 ? 23 25 34 48 56 61 79 82 89 91 99 ? 23 34 48 56 61 79 82 89 91 99 ? ?
Background image of page 9

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

View Full DocumentRight Arrow Icon
List Class with Static Array COMP152 10 Must deal with the issue of type declaration and the size CAPACITY Use typedef mechanism to define type For specific implementation of our class we simply fill in the desired type for Some_Specific_Type typedef Some_Specific_Type ElementType ElementType array[CAPACITY];
Background image of page 10
List Class Example (Static Array Implementation) COMP152 11 Declaration file ( List.h ) Note use of typedef mechanism outside the class This typedef means that it is a list of int Definition and implementation ( List.cpp ) Note considerable steps required for insert() and erase() functions Program to test the class ( listtester.cpp )
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/25/2010 for the course COMP COMP152 taught by Professor D.y.yeung during the Spring '10 term at HKUST.

Page1 / 82

L04_lsq - COMP152 Spring 2010 D.Y. Yeung ADTs: Lists,...

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

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