Chapter19 - CHAPTER 19 Linked Lists Chapter Objectives This chapter discusses I Dynamic data structures in general I A simple dynamic data

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

View Full Document Right Arrow Icon
Chapter Objectives This chapter discusses: ± Dynamic data structures in general ± A simple dynamic data structure—the linked list ± The MATLAB implementation of a linked list ± Useful implementations of linked lists: queues, stacks, and priority queues Linked Lists CHAPTER 19 19.1 Dynamic Data Structure Concepts 19.2 Linked Lists 19.3 MATLAB Implementation of Linked Lists 19.3.1 The LLNode Class 19.3.2 The LinkedList Class 19.4 Processing Linked Lists Recursively 19.5 Implementing Linked List Methods in MATLAB 19.5.1 Building a Linked List 19.5.2 Traversing a Linked List 19.5.3 Mapping a Linked List 19.5.4 Filtering a Linked List 19.5.5 Folding a Linked List 19.5.6 Searching a Linked List 19.6 Applications of Linked Lists 19.6.1 Queues 19.6.2 Stacks 19.6.3 Priority Queues 499
Background image of page 1

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

View Full DocumentRight Arrow Icon
500 Chapter 19 Linked Lists 19.1 Dynamic Data Structure Concepts Having dealt with the concept of modeling specific concrete or abstract objects, we turn to the process of defining dynamically sized collections of objects. The goal is to provide mechanisms that organize collections containing any kind of object—MATLAB basic classes, arrays or structures, cell arrays, or instances of our own classes as defined by the rules discussed in Chapter 18. We will consider three concepts important to dynamic data structures: static memory allocation on the activation stack, dynamic memory allocation from the heap, and dynamically linking objects to create dynamic structures. 19.1.1 Static Memory Allocation In Chapter 1 we discussed the allocation of memory to application programs on a processor in general. The first of these approaches is the activation stack (or simply the stack). The stack is used to allocate memory frames that contain data local to a script or function call. Each overall application program (such as MATLAB) is allocated one memory block for use as its stack. Each time a function is called, a frame of memory is allocated from the stack; when the function terminates, that memory is released from the stack as discussed in Chapter 9. For example, in the middle of a solution to Programming Project 4 in Chapter 5, the activation stack might look like that shown in Figure 19.1. The script containing the variables u , s , and g calls the function roots with parameters A , B , and C . In the core of that function, the square root of a value is called. This would be the state of the stack before the sqrt function completes. The shaded blocks indicate static data storage on the stack for the variables allocated in the script and functions. 19.1.2 Dynamic Memory Allocation The second source of memory discussed in Chapter 1 is the heap, which is a single block of memory available to all the applications to be allocated and deallocated from an application upon request. For example, when we created a BankAccount object for test purposes in Chapter 18, the command was as follows: moola = BankAccount(1000) sqrt x = roots A = Ex6_1 u = 815.2 49.05 40 B = s= -40 40 C = g = 40 9.81 Figure 19.1 An activation stack
Background image of page 2
Figure 19.2 illustrates what actually happens when that command is
Background image of page 3

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

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

This note was uploaded on 11/21/2011 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Page1 / 30

Chapter19 - CHAPTER 19 Linked Lists Chapter Objectives This chapter discusses I Dynamic data structures in general I A simple dynamic data

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

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