{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter19 - CHAPTER 19 Linked Lists Chapter Objectives This...

Info icon This 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 C H A P T E R 1 9 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
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
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
Image of page 2
Figure 19.2 illustrates what actually happens when that command is executed: 1.
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
Image of page 4
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