/**  * This class will use Nodes to form a linked list. It implements the LIFO  * (Last In First Out) methodology to reverse the input string.  *  **/   public class LLStack {              private Node head;              // Constructor with no parameters for outer class       public LLStack( ) {           // to do       }              // This is an inner class specifically utilized for LLStack class,       // thus no setter or getters are needed       private class Node  {          private Object data;          private Node next;                    // Constructor with no parameters for inner class          public Node(){              // to do              // to do          }         // Parametrized constructor for inner class          public Node (Object newData, Node nextLink) {                  // to do: Data part of Node is an Object                 // to do:  Link to next node is a type Node          }       }               // Adds a node as the first node element at the start of the list with the specified data.        public void addToStart(Object itemData) {            // to do             // NOTE: the logic here could be implemented in a single line,            // but not required to be a one liner.        }                // Removes the head node and returns the data Object being         // deleted.        // Returns null if the list is empty.        public Object deleteHead( ) {          // to do        }              // Returns the size of linked list by traversing the list       public int size( ) {            // to do                     }           return count;       }            // Finds if there is match for the given object       public boolean contains(Object item) {           // to do       }              // Finds the first node containing the target item, and returns a       // reference to that node. Return null if target not found.       private Node findData(Object target) {           Node current = head;           Object itemAtPosition;           while (current != null) {               itemAtPosition = current.data;                              if (itemAtPosition.equals(target))                 return current;               current = current.next;             }             return null;            // Target not found!       }                   public void outputList( ) {           Node current = head;           while (current != null) {               System.out.println(current.data);               current = current.next;           }       }              public String toString() {           String retValue = "";           Node current = head;                      while(current != null) {               retValue += current.data.toString() + " ";               current = current.next;           }           return retValue;       }                 public boolean isEmpty( ) {           // to do       }              public void clear( ) {           // to do       }       // For two lists to be equal they must contain the same data items in       // the same order. The equals method of T is used to compare data items.       public boolean equals(Object otherObject) {           if (otherObject == null)             return false;                      else if(!(otherObject instanceof LLStack))             return false;                        else {               LLStack otherList = (LLStack)otherObject;               if (size( )!= otherList.size( ))                 return false;               Node position = head;               Node otherPosition = otherList.head;               while (position != null) {                   if (!(position.data.equals(otherPosition.data)))                     return false;                     position = position.next;                     otherPosition = otherPosition.next;               }               return true;      // objects are the same             }       }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 10PE
icon
Related questions
icon
Concept explainers
Question


/**
 * This class will use Nodes to form a linked list. It implements the LIFO
 * (Last In First Out) methodology to reverse the input string.
 *
 **/

  public class LLStack {
      
      private Node head;
      
      // Constructor with no parameters for outer class
      public LLStack( ) {
          // to do
      }
      
      // This is an inner class specifically utilized for LLStack class,
      // thus no setter or getters are needed
      private class Node  {
         private Object data;
         private Node next;
         
         // Constructor with no parameters for inner class
         public Node(){
             // to do
             // to do
         }
        // Parametrized constructor for inner class
         public Node (Object newData, Node nextLink) {
                 // to do: Data part of Node is an Object
                // to do:  Link to next node is a type Node
         }
      }
      
       // Adds a node as the first node element at the start of the list with the specified data.
       public void addToStart(Object itemData) {
           // to do 
           // NOTE: the logic here could be implemented in a single line,
           // but not required to be a one liner.
       }
       
       // Removes the head node and returns the data Object being 
       // deleted.
       // Returns null if the list is empty.
       public Object deleteHead( ) {
         // to do
       }
      
      // Returns the size of linked list by traversing the list
      public int size( ) {
           // to do
         
          }
          return count;
      }
    
      // Finds if there is match for the given object
      public boolean contains(Object item) {
          // to do
      }
      
      // Finds the first node containing the target item, and returns a
      // reference to that node. Return null if target not found.
      private Node findData(Object target) {
          Node current = head;
          Object itemAtPosition;
          while (current != null) {
              itemAtPosition = current.data;
              
              if (itemAtPosition.equals(target))
                return current;
              current = current.next;
            }
            return null;            // Target not found!
      }
    
      
      public void outputList( ) {
          Node current = head;
          while (current != null) {
              System.out.println(current.data);
              current = current.next;
          }
      }
      
      public String toString() {
          String retValue = "";
          Node current = head;
          
          while(current != null) {
              retValue += current.data.toString() + " ";
              current = current.next;
          }
          return retValue;
      }
  
      
      public boolean isEmpty( ) {
          // to do
      }
      
      public void clear( ) {
          // to do
      }
      // For two lists to be equal they must contain the same data items in
      // the same order. The equals method of T is used to compare data items.
      public boolean equals(Object otherObject) {
          if (otherObject == null)
            return false;
          
          else if(!(otherObject instanceof LLStack))
            return false;
            
          else {
              LLStack otherList = (LLStack)otherObject;
              if (size( )!= otherList.size( ))
                return false;
              Node position = head;
              Node otherPosition = otherList.head;
              while (position != null) {
                  if (!(position.data.equals(otherPosition.data)))
                    return false;
                    position = position.next;
                    otherPosition = otherPosition.next;
              }
              return true;      // objects are the same
            }
      }
      

Expert Solution
Step 1

Here, I have to provide a complete solution to the above-given program.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning