Implement Stack and Queue using LinkList class and compare the performance between StackArray,QueueArray and StackLinkList and QueueLinkList : class LinkList{    private Node first;                                  // ref to first item on list    public Node getFirst()                               // get value of first       { return first; }    public void setFirst(Node f)                       // set first to new link       { first = f; }    public LinkList()                                  // constructor       { first = null; }                                 // no items on list yet    public boolean isEmpty()                           // true if list is empty       { return (first==null); }    public void insertFirst(int dd) {                  // insert at start of list       Node newLink = new Node(dd);                    // make new link       newLink.next = first;                           // newLink --> old first       first = newLink;                                  // first --> newLink       }    public void insertLast(int dd) {                   // insert at start of list       Node newLink = new Node(dd);                    // make new link       Node current = first;       while( current.next != null) {       current = current.next;       }       current.next= newLink;    }// end insertLast    public int deleteFirst(){      // delete first item (assumes list not empty)       Node temp = first;          // save reference to link       first = first.next;         // delete it: first-->old next       temp.next = null;       return temp.iData;          // return deleted link       } // -------------------------------------------------------------    public ListIterator getIterator()       { // return iterator       return new ListIterator(this); // initialized with       }                               //    this list // -------------------------------------------------------------    public void displayList()      {       Node current = first;       // start at beginning of list       while(current != null) {     // until end of list,          current.displayLink();   // print data          current = current.next; // move to next link          }       System.out.println("");       } // -------------------------------------------------------------    public Node find(int key) {    Node current = first;    while ( current != null) {        if(current.iData == key) {        return current;        }//if        current= current.next;    }// while    return null;    }    public Node delete(int key) {    Node prev= first;    Node current = first;    while ( current != null) {        if(current.iData == key) {          prev.next = current.next;          current.next = null;          return current;        }//if       prev = current;        current = current.next;           }// while    return null;    }    public Node deleteLast() {    Node current = first;    Node prev = first;    Node temp = null;    while(current.next != null ) {        prev = current;        current = current.next;    }// end while    temp= current;    prev.next = null;    return temp;    }// end deleteLast // -------------------------------------------------------------    } // end class LinkList     class LinkList2App    {    public static void main(String[] args)       {       LinkList theList = new LinkList(); // make list         theList.insertFirst(22);      // insert 4 items       theList.insertFirst(44);       theList.insertFirst(66);       theList.insertFirst(88);         theList.displayList();              // display list         Node f = theList.find(88);          // find item       if( f != null)          System.out.println("Found link with key " + f.iData);       else          System.out.println("Can't find link");         Node d = theList.delete(66);        // delete item       if( d != null )          System.out.println("Deleted link with key " + d.iData);       else         System.out.println("Can't delete link");         theList.displayList();              // display list       theList.deleteLast();       theList.displayList();       theList.deleteFirst();       theList.displayList();       theList.insertLast(33);       theList.displayList();        theList.insertLast(80);       theList.displayList();       } // end main()    } // end class LinkList2App

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implement Stack and Queue using LinkList class and compare the performance between StackArray,QueueArray and StackLinkList and QueueLinkList :

class LinkList{

   private Node first;                                  // ref to first item on list

   public Node getFirst()                               // get value of first

      { return first; }

   public void setFirst(Node f)                       // set first to new link

      { first = f; }

   public LinkList()                                  // constructor

      { first = null; }                                 // no items on list yet

   public boolean isEmpty()                           // true if list is empty

      { return (first==null); }

   public void insertFirst(int dd) {                  // insert at start of list

      Node newLink = new Node(dd);                    // make new link

      newLink.next = first;                           // newLink --> old first

      first = newLink;                                  // first --> newLink

      }

   public void insertLast(int dd) {                   // insert at start of list

      Node newLink = new Node(dd);                    // make new link

      Node current = first;

      while( current.next != null) {

      current = current.next;

      }

      current.next= newLink;

   }// end insertLast

   public int deleteFirst(){      // delete first item (assumes list not empty)

      Node temp = first;          // save reference to link

      first = first.next;         // delete it: first-->old next

      temp.next = null;

      return temp.iData;          // return deleted link

      }

// -------------------------------------------------------------

   public ListIterator getIterator()       { // return iterator

      return new ListIterator(this); // initialized with

      }                               //    this list

// -------------------------------------------------------------

   public void displayList()      {

      Node current = first;       // start at beginning of list

      while(current != null) {     // until end of list,

         current.displayLink();   // print data

         current = current.next; // move to next link

         }

      System.out.println("");

      }

// -------------------------------------------------------------

   public Node find(int key) {

   Node current = first;

   while ( current != null) {

       if(current.iData == key) {

       return current;

       }//if

       current= current.next;

   }// while

   return null;

   }

   public Node delete(int key) {

   Node prev= first;

   Node current = first;

   while ( current != null) {

       if(current.iData == key) {

         prev.next = current.next;

         current.next = null;

         return current;

       }//if

      prev = current;

       current = current.next;

      

   }// while

   return null;

   }

   public Node deleteLast() {

   Node current = first;

   Node prev = first;

   Node temp = null;

   while(current.next != null ) {

       prev = current;

       current = current.next;

   }// end while

   temp= current;

   prev.next = null;

   return temp;

   }// end deleteLast

// -------------------------------------------------------------

   } // end class LinkList

 

 

class LinkList2App

   {

   public static void main(String[] args)

      {

      LinkList theList = new LinkList(); // make list

 

      theList.insertFirst(22);      // insert 4 items

      theList.insertFirst(44);

      theList.insertFirst(66);

      theList.insertFirst(88);

 

      theList.displayList();              // display list

 

      Node f = theList.find(88);          // find item

      if( f != null)

         System.out.println("Found link with key " + f.iData);

      else

         System.out.println("Can't find link");

 

      Node d = theList.delete(66);        // delete item

      if( d != null )

         System.out.println("Deleted link with key " + d.iData);

      else

        System.out.println("Can't delete link");

 

      theList.displayList();              // display list

      theList.deleteLast();

      theList.displayList();

      theList.deleteFirst();

      theList.displayList();

      theList.insertLast(33);

      theList.displayList();

       theList.insertLast(80);

      theList.displayList();

      } // end main()

   } // end class LinkList2App

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of Threads
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education