{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L04_lsq - COMP152 Spring 2010 D.Y Yeung ADTs Lists Stacks...

Info icon This preview shows pages 1–13. 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
Image of page 1

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

View Full Document Right 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
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?
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

View Full Document Right 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
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 ? ?
Image of page 9

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

View Full Document Right 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];
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 )
Image of page 11

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

View Full Document Right Arrow Icon
List Class with Static Array: Problems COMP152 12
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern