(11) Linear Data Structures

(11) Linear Data Structures - 1 CMSC 132 Object-Oriented...

Info iconThis preview shows pages 1–3. 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 DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CMSC 132: Object-Oriented Programming II Linear Data Structures Department of Computer Science University of Maryland, College Park 2 Reading Read Chapters 4 through 6 in the Koffman text (Chapters 2 through 4 in the second edition) 2 3 Overview Linear data structures General properties of linear data structures Implementations Array Linked list Restricted abstractions Stacks Queues 4 Linear data structures Terminology The head element is the first one in a list; it has no predecessor The tail element is the last one in a list; it has no successor Common operations on linear data structures include: Add an element Remove an element Find an element 5 Adding and removing elements Adding an element Where should it be added? Common choices are At the head (front) of a list At the tail (end) of a list After a particular element Wherever necessary so the list maintains some property (e.g., the elements are in order) Removing an element Which element should be removed? Common choices: Remove the first element Remove the last element Remove the element having a particular value. (But what if that value occurs more than once in a list?) 6 Accessing elements Finding an element Which element should be found? Common choices are: The element at the head (front) of a list The element at the tail (end) of a list The element with a given value The element at a certain position, e.g., the fifth element ( indexing ) By iterating through the list, accessing each element in turn 7 List implementations The two basic implementation techniques for lists are: Store the elements in an array Store the elements in a linked structure Place each element in a separate object (node) 8 Array implementation Advantages The element at any position can be efficiently accessed It uses memory space efficiently Drawbacks It's expensive to insert or remove elements in the...
View Full Document

This note was uploaded on 11/16/2011 for the course CMSC 132 taught by Professor Padua-perez during the Fall '08 term at Maryland.

Page1 / 8

(11) Linear Data Structures - 1 CMSC 132 Object-Oriented...

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

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