Chapter 23 Data Structures (Affordable web design) and Collections 1163 8
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