1166 Data Structures and Collections (Web hosting reseller) Chapter 23 Of
1166 Data Structures and Collections Chapter 23 Of course, the list class contains other methods (such as InsertAtFrontand Remove- FromBack) that we would rather not make accessible through the public interface to the queue class. Remember that all methods in the publicinterface of the Listclass are also publicmethods of the derived class QueueInheritance. When we implement the queue s methods, we have each QueueInheritance method call the appropriate List method method Enqueue calls InsertAtBack, method Dequeuecalls RemoveFromFront, and IsEmptyand Printcalls invoke their base-class versions. Class QueueInheritance does not define methods IsEmpty and Print, because QueueInheritance inherits these methods from class List into QueueInheritance s public interface. Also, the methods in class QueueInheritancedo not use lockstatements. Each of the methods in this class calls a method from class List that uses lock. Note that class QueueInheritance uses namespace LinkedListLibrary (Fig. 23.4); thus, the solution for the class library that defines QueueInheritancemust have a reference to the LinkedListLibraryclass library. Class QueueInheritanceTest s Main method (Fig. 23.14) uses class QueueInheritance to instantiate a queue of objects called queue. Lines 18 21 define four objects that will be enqueued and dequeued. The program enqueues (lines 24, 26, 28 and 30) a boolcontaining true, a charcontaining $, an intcontaining 34567 and a stringcontaining hello. 1 // Fig. 23.13: QueueInheritanceLibrary.cs 2 // Implementing a queue by inheriting from class List. 3 4 using System; 5 using LinkedListLibrary; 6 7 namespace QueueInheritanceLibrary 8 { 9 // class QueueInheritance inherits List’s capabilities 10 public class QueueInheritance : List 11 { 12 // pass name “queue” to List constructor 13 public QueueInheritance() : base( “queue” ) 14 { 15 } 16 17 // place dataValue at end of queue by inserting 18 // dataValue at end of linked list 19 public void Enqueue( object dataValue ) 20 { 21 InsertAtBack( dataValue ); 22 } 23 24 // remove item from front of queue by removing 25 // item at front of linked list 26 public object Dequeue( ) 27 { 28 return RemoveFromFront(); 29 } Fig. 23.13 Fig. 23.13Fig. 23FiFi.13g. 23.13g. 23.13QueueInheritanceextends class List. (Part 1 of 2.)
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services