Question
//class to represent one node in a list class ListNode { //package access members; List can access these directly T data; ListNode nextNode; //constructor creates
//class to represent one node in a list class ListNode
ListNode
//constructor creates a ListNode that refers to object
ListNode( T object ) { this( object, null ); } // end ListNode one-argument constructor
//constructor creates ListNode that refers to //Object and to next ListNode
ListNode( T object, ListNode
//return reference to data in node T getObject() { return data; // return Object in this node } // end method getObject //return reference to next node in list ListNode
//class List definition
public class List
private ListNode
//constructor creates empty List with "list" as the name public List() { this( "list" ); } // end List no-argument constructor
//constructor creates an empty List with a name
public List( String listName ) { name = listName; firstNode = lastNode = null; } // end List one-argument constructor
//insert Object at front of List public void insertAtFront( T insertItem ) { if ( isEmpty() ) // firstNode and lastNode refer to same object
firstNode = lastNode = new ListNode
//insert Object at end of List public void insertAtBack( T insertItem ) { if ( isEmpty() ) // firstNode and lastNode refer to same Object
firstNode = lastNode = new ListNode
lastNode = lastNode.nextNode = new ListNode
//remove first node from List
public T removeFromFront() throws RuntimeException {
if ( isEmpty() ) // throw exception if List is empty throw new RuntimeException( name+" is Empty !!" );
T removedItem = firstNode.data;
// retrieve data being removed
//update references firstNode and lastNode if ( firstNode == lastNode ) firstNode = lastNode = null; else firstNode = firstNode.nextNode; return removedItem; // return removed node data } // end method removeFromFront
//remove last node from List
public T removeFromBack() throws RuntimeException { if ( isEmpty() ) // throw exception if List is empty throw new RuntimeException( name+" is Empty !!" ); T removedItem = lastNode.data; // retrieve data being removed
// update references firstNode and lastNode if ( firstNode == lastNode ) firstNode = lastNode = null; else // locate new last node { ListNode
while ( current.nextNode != lastNode ) current = current.nextNode; lastNode = current; // current is new lastNode
current.nextNode = null; } // end else
return removedItem;
// return removed node data } // end method removeFromBack
//determine whether list is empty public boolean isEmpty() { return firstNode == null; // return true if List is empty } // end method isEmpty
//output List contents public void print() {
if ( isEmpty() ) { System.out.printf( "Empty %s ", name ); return; }
System.out.printf( "The %s is: ", name );
ListNode
while ( current != null ) { System.out.printf( "%s ", current.data ); current = current.nextNode; } // end while System.out.println( " " ); } // end method print } ===========
//class to represent Queue public class Queue
public void print() { queueList.print(); } }
=========== //class to represent Stack
public class Stack
public void push( T item ) { stackList.insertAtFront( item ); }
public T pop() throws RuntimeException { return stackList.removeFromFront(); }
public boolean isEmpty() { return stackList.isEmpty(); }
public void print() { stackList.print(); } }
=============
the question says :
(in java program language) pls I need it fast pls help
Using only the given QueueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started