电动力学chapter4
- 格式:ppt
- 大小:1.13 MB
- 文档页数:71


CHAPTER 11Data StructuresReview Questions1.We need data structures to hold a collection of related variables so that we cansolve complex problems more efficiently.3.An array is a fixed-size sequenced collection of elements of the same data type.5.Elements of an array are contiguous in memory and can be accessed by use of anindex. Elements of a linked list are stored in nodes that may be scattered through-out memory and can only be accessed via the access functions for the list (i.e., aspecific node is returned by a search function).7.A frequency array shows the number of elements with the same value found in aparticular collection of data.9.An array is stored contiguously in memory. A two-dimensional array uses row-major storage in which the array is essentially stored as an array of arrays.11.The fields of a node in a linked list are the data itself and a pointer (address) to thenext node in the list.13.The head pointer contains the address of the first node in the list.15.A singly linked list is a linked list in which each node contains only one pointerthat contains the address of the following node. There are multi-linked lists inwhich each node contains more than one pointer, allowing for much more complexdata structures.Multiple-Choice Questions17.d19.d21.b23.d25.c27.b29.d34CHAPTER 11DATA STRUCTURES31.a33.a35.bExercises37.CompareInput: Two arrays (A and B) of 10 integers1. Set Index equal to 02. While Index is less than 102.1 If A [Index] is not equal to B [Index]2.1.1 Return falseEnd if2.2 Increment IndexEnd loop3. Return trueEnd39.PrintInput: An array (A), the number of rows (I), and the number columns (J)1. Set RowIndex equal to 02. Set ColIndex equal to 03. While RowIndex is less than I3.1 While ColIndex is less than J3.1.1 Print A [RowIndex][ColIndex]3.1.2 Increment ColIndexEnd loop3.2 Move to next line in output3.3 Increment RowIndexEnd loopEnd41.AddFractionsInput: Two fractions (Fr1 and Fr2)1. Allocate new fraction object (Fr3)2. Set Fr3.denominator equal to Fr1.denominator * Fr2.denominator3. Set Fr3.numerator equal to (Fr1.numerator * Fr2.denominator) +(Fr2.numerator *Fr1.denominator)4. Return Fr3EndSECTION 543.MultiplyFractionsInput: Two fractions (Fr1 and Fr2)1. Allocate new fraction object (Fr3)2. Set Fr3.denominator equal to Fr1.denominator * Fr2.denominator3. Set Fr3.numerator equal to Fr1.numerator * Fr2.numerator4. Return Fr3End45.See Figure 11.1Figure 11.1Exercise 4547.When an element is to be added to the array, a new array must be allocated and allof the old elements and the new element must be moved to the new array.49.Adding an element to a linked list is easier because a linked list does not have to betotally reallocated.51.Accessing an element of an array is easier because an index can be used.53.Sorting an array is easier because the elements can just be swapped rather thanhaving to redirect up to four different pointers.6CHAPTER 11DATA STRUCTURESSECTION 78CHAPTER 11DATA STRUCTURES。