Archive for April, 2007

1164 Data Structures and Collections Chapter 23 (continued (Dedicated web hosting)

Monday, April 30th, 2007

1164 Data Structures and Collections Chapter 23 (continued from previous page) The stack is: 34567 $ True The stack is: hello 34567 $ True hello popped The stack is: 34567 $ True 34567 popped The stack is: $ True $ popped The stack is: True True popped Empty stack at LinkedListLibrary.List.RemoveFromFront() in z:ch23linkedlistlibrarylinkedlistlibrary.cs:line 114 at StackInheritanceLibrary.StackInheritance.Pop() in z:ch23stackinheritancelibrary stackinheritancelibrary.cs:line 28 at StackInheritanceTest.StackInheritanceTest.Main(String[] args in z:ch23fig23_11stackinheritancetest.cs:line 41 Fig. 23.11 Fig. 23.11Fig. 23FiFi.11g. 23.11g. 23.11Using class StackInheritance. (Part 3 of 3.) 1 // Fig. 23.12: StackCompositionLibrary.cs 2 // StackComposition definition with composed List object. 3 4 using System; 5 using LinkedListLibrary; 6 7 namespace StackCompositionLibrary 8 { 9 // class StackComposition encapsulates List’s capabilities 10 public class StackComposition 11 { 12 private List stack; 13 14 // construct empty stack 15 public StackComposition() 16 { 17 stack = new List( “stack” ); 18 } 19 20 // add object to stack 21 public void Push( object dataValue ) 22 { 23 stack.InsertAtFront( dataValue ); 24 } 25 Fig. 23.12 Fig. 23.12Fig. 23FiFi.12g. 23.12g. 23.12StackCompositionclass encapsulates functionality of class List. (Part 1 of 2.)
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Chapter 23 Data Structures (Affordable web design) and Collections 1163 8

Monday, April 30th, 2007

Chapter 23 Data Structures and Collections 1163 8 namespace StackInheritanceTest 9 { 10 // demonstrate functionality of class StackInheritance 11 class StackInheritanceTest 12 { 13 static void Main( string[] args ) 14 { 15 StackInheritance stack = new StackInheritance(); 16 17 // create objects to store in the stack 18 bool aBoolean = true; 19 char aCharacter = ‘$’; 20 int anInteger = 34567; 21 string aString = “hello”; 22 23 // use method Push to add items to stack 24 stack.Push( aBoolean ); 25 stack.Print(); 26 stack.Push( aCharacter ); 27 stack.Print(); 28 stack.Push( anInteger ); 29 stack.Print(); 30 stack.Push( aString ); 31 stack.Print(); 32 33 // use method Pop to remove items from stack 34 try 35 { 36 while ( true ) 37 { 38 object removedObject = stack.Pop(); 39 Console.WriteLine( removedObject + ” popped” ); 40 stack.Print(); 41 } 42 } 43 44 // if exception occurs, print stack trace 45 catch ( EmptyListException emptyListException ) 46 { 47 Console.Error.WriteLine( 48 emptyListException.StackTrace ); 49 } 50 51 } // end method Main 52 53 } // end class StackInheritanceTest 54 } The stack is: True The stack is: $ True (continued on next page) Fig. 23.11 Fig. 23.11Fig. 23FiFi.11g. 23.11g. 23.11Using class StackInheritance. (Part 2 of 3.)
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

Web hosting directory - 1162 Data Structures and Collections Chapter 23 6

Sunday, April 29th, 2007

1162 Data Structures and Collections Chapter 23 6 7 namespace StackInheritanceLibrary 8 { 9 // class StackInheritance inherits class List’s capabilities 10 public class StackInheritance : List 11 { 12 // pass name “stack” to List constructor 13 public StackInheritance() : base( “stack” ) 14 { 15 } 16 17 // place dataValue at top of stack by inserting 18 // dataValue at front of linked list 19 public void Push( object dataValue ) 20 { 21 InsertAtFront( dataValue ); 22 } 23 24 // remove item from top of stack by removing 25 // item at front of linked list 26 public object Pop() 27 { 28 return RemoveFromFront(); 29 } 30 31 } // end class StackInheritance 32 } Fig. 23.10 Fig. 23.10Fig. 23FiFi.10g. 23.10g. 23.10StackInheritanceextends class List. (Part 2 of 2.) Another way to implement a stack class is by reusing a list class through composition. The class in Fig. 23.12 uses a privateobject of class List(line 12) in the definition of class StackComposition. Composition enables us to hide the methods of class List that should not be in our stack s public interface by providing public interface methods only to the required Listmethods. This class implements each stack method by delegating its work to an appropriate Listmethod. In particular, StackComposition calls List methods InsertAtFront, RemoveFromFront, IsEmpty and Print. In this example, we do not show class StackCompositionTest, because the only difference in this example is that we change the type of the stack from StackInheritance to StackComposition. If you execute the application from the code on the CD that accompanies this book, you will see that the output is identical. 1 // Fig. 23.11: StackInheritanceTest.cs 2 // Testing class StackInheritance. 3 4 using System; 5 using StackInheritanceLibrary; 6 using LinkedListLibrary; 7 Fig. 23.11 Fig. 23.11Fig. 23FiFi.11g. 23.11g. 23.11Using class StackInheritance. (Part 1 of 3.)
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

Chapter 23 Data Structures and Collections 1161 We (Free web servers)

Sunday, April 29th, 2007

Chapter 23 Data Structures and Collections 1161 We take advantage of the close relationship between lists and stacks to implement a stack class by reusing a list class. We demonstrate two different forms of reusability. First, we implement the stack class by inheriting from class Listof Fig. 23.4. Then, we implement an identically performing stack class through composition by including a List object as a private member of a stack class. This chapter implements list, stack and queue data structures to store object references to encourage further reusability. Thus, any object type can be stored in a list, stack or queue. The program of Fig. 23.10 and Fig. 23.11 creates a stack class by inheriting from class Listof Fig. 23.4. We want the stack to have methods Push, Pop, IsEmptyand Print. Essentially, these are the methods InsertAtFront, RemoveFromFront, IsEmpty and Print of class List. Of course, class List contains other methods (such as InsertAtBack and RemoveFromBack) that we would rather not make accessible through the publicinterface of the stack. It is important to remember that all methods in the public interface of class List are also public methods of the derived class StackInheritance(Fig. 23.10). When we implement the stack s methods, we have each StackInheritance method call the appropriate List method method Push calls InsertAtFront, method Pop calls RemoveFromFront. Class StackInheritance does not define methods IsEmpty and Print, because StackInheritance inherits these methods from class List into StackInheritance s publicinterface. The methods in class StackInheritancedo not use lockstatements. Each of the methods in this class calls a method from class List that uses lock. If two threads call Push on the same stack object, only one of the threads at a time will be able to call List method InsertAt- Front. Note that class StackInheritanceuses namespace LinkedListLibrary (Fig. 23.4); thus, the solution for the class library that defines StackInheritancemust have a reference to the LinkedListLibraryclass library. StackInheritanceTest s Main method (Fig. 23.11) uses class Stack- Inheritanceto instantiate a stack of objects called stack. Lines 18 21 define four objects that will be pushed onto the stack and popped off the stack. The program pushes onto the stack (lines 24, 26, 28 and 30) a boolcontaining true, a charcontaining $, an intcontaining 34567and a stringcontaining hello. An infinite whileloop (lines 36 41) pops the elements from the stack. When there are no objects left to pop, method Popthrows an EmptyListExceptionand the program displays the exception s stack trace, which shows the program execution stack at the time the exception occurred. The program uses method Print (inherited from class List) to output the contents of the stack after each operation. Note that class StackInheritanceTest uses namespace LinkedListLibrary (Fig. 23.4) and namespace StackInheritanceLibrary (Fig. 23.10); thus, the solution for class StackInheritanceTest must have references to both class libraries. 1 // Fig. 23.10: StackInheritanceLibrary.cs 2 // Implementing a stack by inheriting from class List. 3 4 using System; 5 using LinkedListLibrary; Fig. 23.10 Fig. 23.10Fig. 23FiFi.10g. 23.10g. 23.10StackInheritanceextends class List. (Part 1 of 2.)
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

1160 Data Structures and (Most popular web site) Collections Chapter 23 firstNode(a)

Sunday, April 29th, 2007

1160 Data Structures and Collections Chapter 23 firstNode(a) 7 1112 lastNode 5 (b) firstNode current lastNode 7 1112 5 removeItem Fig. 23.9 Fig. 23.Fig. 23.FF9ig. 23.9ig.9A graphical representation of the RemoveFromBackoperaton. 23. i 23.4 Stacks A stack is a constrained version of a linked list a stack takes new nodes and releases nodes only at the top. For this reason, a stack is referred to as a last-in, first-out (LIFO) data structure. The link member in the bottom (i.e., last) node of the stack is set to nullto indicate the bottom of the stack. The primary operations to manipulate a stack are push and pop. Operation push adds a new node to the top of the stack. Operation pop removes a node from the top of the stack and returns the item from the popped node. Stacks have many interesting applications. For example, when a program calls a method, the called method must know how to return to its caller, so the return address is pushed onto the program execution stack. If a series of method calls occurs, the successive return values are pushed onto the stack in last-in, first-out order so that each method can return to its caller. Stacks support recursive method calls in the same manner that they do conventional nonrecursive method calls. The program-execution stack contains the space created for local variables on each invocation of a method during a program s execution. When the method returns to its caller, the space for that method’s local variables is popped off the stack, and those variables are no longer known to the program. The System.Collections namespace contains class Stack for implementing and manipulating stacks that can grow and shrink during program execution. Section 23.7 discusses class Stack.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

Chapter 23 Data Structures and Collections 1159 3. (Cheap web hosting)

Saturday, April 28th, 2007

Chapter 23 Data Structures and Collections 1159 3. If the list has more than one node prior to removal, create the ListNode reference currentand assign it firstNode(line 147). 4. Now walk the list with current until it references the node before the last node. The while loop (lines 150 151) assigns current.Next to reference currentas long as current.Nextis not equal to lastNode. 5. After locating the second-to-last node, assign currentto lastNode(line 154) to dethread the last node from the list. 6. Set current.Nextto null(line 155) in the new last node of the list to ensure proper list termination. 7. Return the removeItemreference (line 140). Fig. 23.9 illustrates method RemoveFromBack. Part a) illustrates the list before the removal operation. Part b) shows the actual reference manipulations. Method Print (Fig. 23.4, lines 172 195) first determines whether the list is empty (line 176). If so, Print displays a string consisting of the string “Empty ” and the list s name, then returns control to the calling method. Otherwise, Printoutputs the data in the list. The method prints a string consisting of the string “The “, the name and the string ” is:”. Then, line 184 creates ListNodereference currentand initializes it with firstNode. While currentis not null, there are more items in the list. Therefore, the method prints current.Data (line 189), then assigns current.Next to current (line 190) to move to the next node in the list. Note that, if the link in the last node of the list is not null, the printing algorithm will erroneously attempt to print past the end of the list. The printing algorithm is identical for linked lists, stacks and queues. (a) firstNode lastNode 7 1112 5 (b) firstNode lastNode 7 1112 5 removeItem Fig. 23.8 Fig. 23.Fig. 23.FF8ig. 23.8ig.8A graphical representation of the RemoveFromFrontoperation. 23.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

Professional web hosting - 1158 Data Structures and Collections Chapter 23 1.

Saturday, April 28th, 2007

1158 Data Structures and Collections Chapter 23 1. Assign lastNode.Data (the data being removed from the list) to reference removeItem(line 139). 2. If the objects to which firstNode and lastNode refer are the same object (line 142), the list has only one element prior to the removal attempt. In this case, the method sets firstNodeand lastNodeto null(line 143) to dethread (remove) that node from the list (leaving the list empty). (a) firstNode 7 11 New ListNode 12 (b) firstNode New ListNode 7 11 12 Fig. 23.6 Fig. 23.Fig. 23.FF6ig. 23.6ig.6A graphical representation of the InsertAtFrontoperation. 23. (a) firstNode lastNode New ListNode 7 1112 5 (b) firstNode lastNode New ListNode 12 7 11 5 Fig. 23.7 Fig. 23.Fig. 23.FF7ig. 23.7ig.7A graphical representation of the InsertAtBackoperation. 23.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

Business web hosting - Chapter 23 Data Structures and Collections 1157 Fig.

Friday, April 27th, 2007

Chapter 23 Data Structures and Collections 1157 Fig. 23.6 illustrates method InsertAtFront. Part (a) of the figure shows the list and the new node during the InsertAtFront operation and before the threading of the new node into the list. The dotted arrows in part (b) illustrate step 3 of the InsertAt- Front operation, which enables the node containing 12 to become the new list front. Method InsertAtBack (Fig. 23.4, lines 92 104) places a new node at the back of the list. The method consists of three steps (illustrated in Fig. 23.7): 1. Call IsEmpty to determine whether the list is empty (line 96). 2. If the list is empty, set both firstNode and lastNode to refer to a new ListNode initialized with insertItem (lines 97 98). The ListNode constructor at lines 16 19 (Fig. 23.4) calls the ListNode constructor at lines 23 27 (Fig. 23.4) to set instance variable data to refer to the object passed as the first argument and sets the next reference to null. 3. If the list is not empty, thread the new node into the list by setting lastNode and lastNode.next to refer to a new ListNode object initialized with insertItem (lines 101 102). When the ListNode constructor (lines 16 19 of Fig. 23.4) executes, it sets instance variable data to refer to the object passed as an argument and sets the next reference to null. Fig. 23.7 illustrates an InsertAtBack operation. Part a) of the figure shows the list and the new node during the InsertAtBackoperation and before the new node has been threaded into the list. The dotted arrows in part b) illustrate the steps of method Insert- AtBack that enable a new node to be added to the end of a list that is not empty. Method RemoveFromFront (Fig. 23.4, lines 107 127) removes the front node of the list and returns a reference to the removed data. The method throws an EmptyList- Exception (line 114) if the programmer tries to remove a node from an empty list. Otherwise, the method returns a reference to the removed data. The method consists of four steps (illustrated in Fig. 23.8): 1. Assign firstNode.Data (the data being removed from the list) to reference removeItem (line 116). 2. If the objects to which firstNode and lastNode refer are the same object, the list has only one element prior to the removal attempt. In this case, the method sets firstNode and lastNode to null (line 120) to dethread (remove) the node from the list (leaving the list empty). 3. If the list has more than one node prior to removal, then the method leaves reference lastNode as is and simply assigns firstNode.Next to reference firstNode (line 123). Thus, firstNodereferences the node that was the second node prior to the RemoveFromFront call. 4. Return the removeItem reference. Fig. 23.8 illustrates method RemoveFromFront. Part a) illustrates the list before the removal operation. Part b) shows actual reference manipulations. Method RemoveFromBack (Fig. 23.4, lines 130 160) removes the last node of a list and returns a reference to the removed data. The method throws an EmptyListException( line 137) if the program attempts to remove a node from an empty list. The method consists of several steps (illustrated in Fig. 23.9):
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services

1156 Data Structures (Michigan web site) and Collections Chapter 23 35

Friday, April 27th, 2007

1156 Data Structures and Collections Chapter 23 35 // remove data from list and print after each removal 36 try 37 { 38 removedObject = list.RemoveFromFront(); 39 Console.WriteLine( removedObject + ” removed” ); 40 list.Print(); 41 42 removedObject = list.RemoveFromFront(); 43 Console.WriteLine( removedObject + ” removed” ); 44 list.Print(); 45 46 removedObject = list.RemoveFromBack(); 47 Console.WriteLine( removedObject + ” removed” ); 48 list.Print(); 49 50 removedObject = list.RemoveFromBack(); 51 Console.WriteLine( removedObject + ” removed” ); 52 list.Print(); 53 } 54 55 // process exception if list empty when attempt is 56 // made to remove item 57 catch ( EmptyListException emptyListException ) 58 { 59 Console.Error.WriteLine( “n” + emptyListException ); 60 } 61 62 } // end method Main 63 64 } // end class ListTest 65 } The list is: True The list is: $ True The list is: $ True 34567 The list is: $ True 34567 hello $ removed The list is: True 34567 hello True removed The list is: 34567 hello hello removed The list is: 34567 34567 removed Empty list Fig. 23.5 Fig. 23.FiFig. 23.5g. 23.5Demonstrating the linked list. (Part 2 of 2.) Fig. 23.5
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

Chapter 23 Data Structures and Collections 1155 195 (Web design company)

Thursday, April 26th, 2007

Chapter 23 Data Structures and Collections 1155 195 // class EmptyListException definition 196 public class EmptyListException : ApplicationException 197 { 198 public EmptyListException( string name ) 199 : base( “The ” + name + ” is empty” ) 200 { 201 } 202 203 } // end class EmptyListException 204 205 } // end namespace LinkedListLibrary Fig. 23.4 Fig. 23.4Fig. 23FiFi.4g. 23.4g.23.4Definitions of classes ListNode, Listand EmptyListException. (Part 5 of 5.) 1 // Fig 23.5: ListTest.cs 2 // Testing class List. 3 4 using System; 5 using LinkedListLibrary; 6 7 namespace ListTest 8 { 9 // class to test List class functionality 10 class ListTest 11 { 12 static void Main( string[] args ) 13 { 14 List list = new List(); // create List container 15 16 // create data to store in List 17 bool aBoolean = true; 18 char aCharacter = ‘$’; 19 int anInteger = 34567; 20 string aString = “hello”; 21 22 // use List insert methods 23 list.InsertAtFront( aBoolean ); 24 list.Print(); 25 list.InsertAtFront( aCharacter ); 26 list.Print(); 27 list.InsertAtBack( anInteger ); 28 list.Print(); 29 list.InsertAtBack( aString ); 30 list.Print(); 31 32 // use List remove methods 33 object removedObject; 34 Fig. 23.5 Fig. 23.FiFig. 23.5g. 23.5Demonstrating the linked list. (Part 1 of 2.) Fig. 23.5
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services