Question

implementing the stack ADT with singly linked list Theoretical Questions, pot - Adobe Acrobat Reader DC File Edit View Sign Window Help Home Tools Theoretical Questio. * Sign I

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Implelemtation Stack using LinkedList<Generics>:

public class StackusingLL<T> {


Node<T> head;
int size;


public StackusingLL() {
   head=null;
   size=0;
}


public int size() {
   return size;
  
}


public boolean isempty()
{
   if(size()==0) {
       return true;
   }


   return false;
}


  
public T top() throws Stackemptyexception{
   if(head==null) {
       Stackemptyexception e= new Stackemptyexception();
       throw e;
   }
   return head.data;
}


  
public void push(T ele) {
   Node<T>newnode= new Node<T>( ele);
   newnode.next=head;
   head=newnode;
   size++;
}


  
public T pop() throws Stackemptyexception{
   if(head==null) {
       Stackemptyexception e= new Stackemptyexception();
       throw e;
   }
   Node<T>temp=null;
   temp=head;
   head=head.next;
   size--;
   return temp.data;
}
  
  
  
}

------------class Node-----------


class Node<T>
{
   T data;
   Node next;
     
   Node(T data){
       {
           this.data=data;
           next=null;
       }
   }

  
   }

---------------------Stackemptyexception class--------------

public class Stackemptyexception extends Exception {

}

-------------------Implememtation---------------------

public class Stackuse {

   public static void main(String[] args) throws Stackfullexception {
      
       StackusingLL<Integer> b= new StackusingLL<Integer>();
      
      
       System.out.print("Push operations : ");
       for(int i=0;i<=5;i++) {
           System.out.print(i+" ");
       b.push(i);
}
      
       System.out.println();
      
       System.out.print("pop operations : ");
      
       while(!b.isempty()) {
          try{
                   System.out.print(b.pop()+" ");        }
           catch(Stackemptyexception e) {
                   System.out.println("Stackemptyexception");
               }
           }
      
      
      
   }
   }

SAMPLE OUTPUT:

Console X Call Hierarchy <terminated> Stackuse (1) [Java Application] C:\Program Files\Java\jdk-13.0.2\bin\javaw.exe Push ope

// PLEASE THUMBS-UP AND RATE POSITIVELY

If you have any doubt regarding this question ask me in comments

THANK YOU:-)

Add a comment
Know the answer?
Add Answer to:
implementing the stack ADT with singly linked list Theoretical Questions, pot - Adobe Acrobat Reader DC...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 201Btinal.pdt- Adobe Acrobat Reader DC ile dit View Windaw Help OA sign In Home Tools RIC...

    201Btinal.pdt- Adobe Acrobat Reader DC ile dit View Windaw Help OA sign In Home Tools RIC ?nd order ).p... Fundamentals of FL... 7018finalpdf X ti Share → Export PDF Create PDF 2. Deterinoand fo for the circuit shown Adobe PDF Pack 4 kQ Convert files to PD and easily combine them with file types with a paid 2V 2ks2 Select File to Convert to PDF Sclect File Edit PDF Comment Combine Files Organize Pages Redact Send, sign, and track PDFs...

  • X assign30.pat - Adobe Acrobat Reader DC File Edit View Window Help Home Tools sched.pdf :...

    X assign30.pat - Adobe Acrobat Reader DC File Edit View Window Help Home Tools sched.pdf : notes.pdf assign27.pdf assign78.pdf assign29.pdf assign30.pdf x assign31.pdf assign32.pdf 2 1. Share Search 'Highlight 67. A cube is expanding in such a way that the length of each edge at time t is r = 2 + + +1. Export PDF (3) a. At what rate is the volume increasing when t = 2? Create PDF Adobe PDF Pack Corrent files to PDF and easily...

  • - х Introduction to Financial Accounting (BBAC 1013) 2020 S2 (Exam paper).pdf - Adobe Acrobat Reader...

    - х Introduction to Financial Accounting (BBAC 1013) 2020 S2 (Exam paper).pdf - Adobe Acrobat Reader DC File Edit View Sign Window Help Home Tools Introduction to Fin... X Chapter 6 -Bank re... Extra exercise - Ban... Sign In 1 3/6 114% Search "Hide Text' Q2. Export PDF Adobe Export PDF Convert PDF Files to Word or Excel Online Select PDF File Successful Enterprise Sdn Bhd is preparing the bank reconciliation for the month of December 2019. The cash general...

  • Final Semi 20182019 03 04.pdt - Adobe Acrobat Reader DC File Edit View Window Help Home...

    Final Semi 20182019 03 04.pdt - Adobe Acrobat Reader DC File Edit View Window Help Home Tools ilovepdf merged (4). Final Sem 1 2018201... x Sign In (1 of 2) 125% Jo Share Search 'Crop Page (b) D. Export PDF Edit PDF A pump operates at 1200 rpm with blade thickness occupied 12 percent of the circumference. The specifications of the pump are as below: Parameter Inlet Outlet Radius, r (mm) 150 Blade width, b (mm) 10 7 Blade angle,...

  • Assa3pdt Adobe Acrobat Reader D ile Edit Vie Windaw Help Home Tools Assg3.pdf × MATH1100M updat.....

    QUESTION number #3 Assa3pdt Adobe Acrobat Reader D ile Edit Vie Windaw Help Home Tools Assg3.pdf × MATH1100M updat.. MATH13COM 43-4... 13536 ti Share » Write your name on each page and number each page * Clearly indicate which problem you are solving * Submit your assignments at the beginning of the class on April 02, 2019 → Export PDF Adobe Export PDF Convert PDF Files to Word or Excel Online Selact PDF File 1. (20 points) Find a formula...

  • Corporate Finance Core Principles and Applications 5th Edition by Stephen Ross (1).pdf - Adobe Acrobat Reader...

    Corporate Finance Core Principles and Applications 5th Edition by Stephen Ross (1).pdf - Adobe Acrobat Reader DC File Edit View Window Help Home Tools Corporate Finance X Sign In 0 Θ T 也Share 229 (262 of 721) 104%. At least one signature has problems. Signature Panel Export PDF Seth Bullock, the owner of Bullock Gold Mining, is eveluating a new gold mine in South Dakota. Dan Dority, the company's geologist, has just firished his analysis of the mine site. He...

  • Can someone answer the questions above and explain them to me lecture_13_oxidative_phosphorylation_2 2019 post.pdf - Adobe...

    Can someone answer the questions above and explain them to me lecture_13_oxidative_phosphorylation_2 2019 post.pdf - Adobe Acrobat Reader DC File Edit View Window Help Home Tools Untitled document lecture 13_oxidativ...X Sign In +) 643% Share Export PDF Create PDF The P/O ratio reflects the ratio of ATPs synthesized per pair of electrons consumed OE Edit PDF lf 5 protons are required required to drive the synthesis of 1 ATP and 10 protons are pumped from a pair of reducing equivalents...

  • Need help with physics questions involving math. Please 쇠 Hw4(4).pdf-Aciooe Acrobat Redder DC File Edit V...

    Need help with physics questions involving math. Please 쇠 Hw4(4).pdf-Aciooe Acrobat Redder DC File Edit V Window Help Home Tools Nvaldo J. Tro - Ch Sign In t1 Share 1) As you are rnning you think of a clever t-shirt design. You decide to get the t-shirts printed profession- ally with the intention of seling them to make a profit. The table bclow outlincs the cost (in $) of getting a certain number (N) of t-shirts printed Export PDF Create...

  • The simple pendulum shown above consists of a 0.8 kg bob suspended from the end of...

    The simple pendulum shown above consists of a 0.8 kg bob suspended from the end of a l = 1.5 m long chord. While the pendulum is swinging, an obstacle is placed a distance of 3l/4 directly beneath the pivot. Find the period of the pendulum now that this obstacle has been placed in its path. Acrobat Reader File Edit View Window Help 896 D Sat 10:40 PM a Physics 2014: General Physics l Home Tools Sign In Physics 2014:...

  • in c++ please include all of the following " template class, template function, singly linked list,...

    in c++ please include all of the following " template class, template function, singly linked list, the ADT stack, copy constructor, operator overloading, "try catch"and pointers Modify the code named "Stack using a Singly Linked List" to make the ADT Stack that is a template class has the code of the destructor in which each node is directly deleted without using any member function. As each node is deleted, the destructor displays the address of the node that is being...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT