Top web site - Chapter 23 Data Structures and Collections 1149 Performance
Chapter 23 Data Structures and Collections 1149 Performance Tip 23.1 An array can be declared to contain more elements than the number of items expected, at the expense of wasting memory. Linked lists provide better memory utilization in these situations and they allow the program to adapt at run time. Performance Tip 23.2 After locating the insertion point for a new item in a sorted linked list, inserting an element in the list is fast only two references have to be modified. All existing nodes remain at their current locations in memory. Programmers can maintain linked lists in sorted order simply by inserting each new element at the proper point in the list (locating the proper insertion point does take time). They do not need to move existing list elements. Performance Tip 23.3 The elements of an array are stored contiguously in memory to allow immediate access to any array element the address of any element can be calculated directly from its offset from the beginning of the array. Linked lists do not afford such immediate access to their elements an element can be accessed only by traversing the list from the front. Memory does not normally store linked list nodes contiguously. Rather, the nodes are logically contiguous. Figure 23.3 illustrates a linked list with several nodes. Performance Tip 23.4 Using dynamic memory allocation (instead of arrays) for data structures that grow and shrink at execution time can save memory. Keep in mind, however, that references occupy space, and that dynamic memory allocation incurs the overhead of method calls. The program of Fig. 23.4 Fig. 23.5 uses an object of class List to manipulate a list of miscellaneous object types. The Mainmethod of class ListTest(Fig. 23.5) creates a list of objects, inserts objects at the beginning of the list using Listmethod InsertAt- Front, inserts objects at the end of the list using Listmethod InsertAtBack, deletes objects from the front of the list using List method RemoveFromFront and deletes objects from the end of the list using List method RemoveFromBack. Each insertion and deletion operation invokes Listmethod Printto display the current list contents. A detailed discussion of the program follows. If an attempt is made to remove an item from an empty list, an EmptyListExceptionoccurs. firstNode lastNode …H D Q Fig. 23.3 Fig. 23.Fig. 23.FF3ig. 23.3ig.3A graphical representation of a linked list. 23.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services