Chapter 23 Data (Web server info) Structures and Collections 1167 30
Chapter 23 Data Structures and Collections 1167 30 31 } // end of QueueInheritance 32 } Fig. 23.13 Fig. 23.13Fig. 23FiFi.13g. 23.13g. 23.13QueueInheritanceextends class List. (Part 2 of 2.) An infinite while loop (lines 39 44) dequeues the elements from the queue in FIFO order. When there are no objects left to dequeue, method Dequeue throws an Empty- ListException and 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 queue after each operation. Note that class QueueInheritanceTest uses namespace LinkedListLibrary (Fig. 23.4) and namespace QueueInheritanceLibrary(Fig. 23.13); thus, the solution for class QueueInheritanceTestmust have references to both class libraries. 1 // Fig. 23.14: QueueTest.cs 2 // Testing class QueueInheritance. 3 4 using System; 5 using QueueInheritanceLibrary; 6 using LinkedListLibrary; 7 8 namespace QueueTest 9 { 10 // demonstrate functionality of class QueueInheritance 11 class QueueTest 12 { 13 static void Main( string[] args ) 14 { 15 QueueInheritance queue = new QueueInheritance(); 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 Enqueue to add items to queue 24 queue.Enqueue( aBoolean ); 25 queue.Print(); 26 queue.Enqueue( aCharacter ); 27 queue.Print(); 28 queue.Enqueue( anInteger ); 29 queue.Print(); 30 queue.Enqueue( aString ); 31 queue.Print(); 32 33 // use method Dequeue to remove items from queue 34 object removedObject = null; 35 Fig. 23.14 Fig. 23.1FiFig. 23.14g. 23.14 Fig. 23.14 Using inheritance to create a queue. (Part 1 of 2.)
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services