Question

1. a. Stack b. Queue c. Priority Queue d. List - (ADTs)  Given the following steps: push(...

1. a. Stack b. Queue c. Priority Queue d. List - (ADTs)  Given the following steps:

push( "Jane" );
push( "Jess" );
push( "Jill" );
push( pop() );
push( "Jim" );

String name = pop();
push( peek() );

Write separate programs for each of the data structures Stack, Queue, PriorityQueue, and List. Use the appropriate push(), pop(), peek() for each of the respective ADT's. Use the Java class library of the ADT's as opposed to the author's implementation.

  1. What is in a stack with these steps? (Java class Stack p174)
  2. What is in a queue with these steps? (Java interface Queue p219)   
  3. What is in a priority queue with these steps? (Java class PriorityQueue p229)
  4. What is in a list with these steps? (Java interface List p308)   

2.  (Queue) Use a queue to reverse the order of a Stack s0 = { 1, 22, 333, 4444, 55555 }. (Note: 55555 is the top of the stack.)

3. (Recursion) Write a recursive method for the function t(n) and a main() with n = 5.   

               t(1) = 2

               t(n) = 1 + t(n – 1) for n > 1

4.  (List) Write Java statements at the client level that return the position of a given object in the list myList. Assume that the object is in the list. Use the list myList = { Amy, Elias, Bob, Drew, Aaron, Carol }. Find Drew in position i=3.

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

2)

import java.util.LinkedList;

import java.util.Stack;

public class Main {

public static void main(String[] args) {

Stack<Integer> st = new Stack<>();

st.add(1);

st.add(22);

st.add(333);

st.add(4444);

st.add(55555);

  

Queue<Integer> q = new LinkedList<>();

  

while(!st.isEmpty()) {

q.add(st.pop());

}

  

while (!q.isEmpty()) {

st.push(q.remove());

}

System.out.println(st);

}

}

3)

public static int recur(int n) {

if (n == 1) {

return 2;

}

return recur(n-1) + 1;

}

  

public static void main(String[] args) {

System.out.println(recur(5));

}

NOTE: As per Chegg policy I am allowed to answer specific number of questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.

Add a comment
Know the answer?
Add Answer to:
1. a. Stack b. Queue c. Priority Queue d. List - (ADTs)  Given the following steps: push(...
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
  • Create a flowchart to represent the Push and Pop operations for a Stack based on a linked list data structure. Create a flowchart to represent the Enqueue and Dequeue operations for a Queue based on a...

    Create a flowchart to represent the Push and Pop operations for a Stack based on a linked list data structure. Create a flowchart to represent the Enqueue and Dequeue operations for a Queue based on a linked list data structure. Write the required Java code to implement either a Stack or a Queue data structure based on a linked list. The code should include the class constructors, the necessary properties, and methods to add and remove elements from the data...

  • e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return t...

    e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...

  • Develop a generic stack ADT class by once again implementing the StackInterface.java and use Queue object...

    Develop a generic stack ADT class by once again implementing the StackInterface.java and use Queue object as underlying ADT(implement stack using queue) Include two constructors: one that sets the capacity at 100 elements, and the other that allows the application level to provide a capacity value as an actual parameter with the constructor call. Also include a toString method. StackInterface : package interfaces; public interface StackInterface<E> { void push(E element); // add an element to the stack - always at...

  • I already created a doubly linked list class. I need help doing this and adding the...

    I already created a doubly linked list class. I need help doing this and adding the doubly linked list class to this. I need this for Java language if someone can please help me Step 2 Stack and Queue Using the linked list class you created in Step 1 create stack and queue classes. Iwill leave it up to you as to whether to use composition or inheritance but whatever way you choose to go you should be able to...

  • A priority queue is a collection of items each having a priority. A priority queue supports three...

    A priority queue is a collection of items each having a priority. A priority queue supports three fundamental operations. You can ask a priority queue whether it is empty. You can insert an item into the priority queue with a given priority. You can remove the item from the priority queue that has the smallest priority. For example, suppose that you start with an empty priority queue and imagine performing the following steps. Insert item "one" with priority 10. Insert...

  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • In Java language: 1. The complement of a queue is a stack. It uses first-in, last-out...

    In Java language: 1. The complement of a queue is a stack. It uses first-in, last-out accessing and is often likened to a stack of plates. The first plate put on the table is the last plate used. Create a stack class called Stack that can hold characters. Call the methods that access the stack push( ) and pop( ). Allow the user to specify the size of the stack when it is created. Keep all other members of the...

  • ANSWER IN JAVA ASAP 1.Implement a stack on the singly linked list with the operations of...

    ANSWER IN JAVA ASAP 1.Implement a stack on the singly linked list with the operations of Lab Assignment 1. Hint: Using the same Stack class you implemented, change the array to an object of the singly linked list class. The functionality of push and pop is now based on the methods of the linked list class.

  • Using Java You are given a Node class and a List class: public class Node {...

    Using Java You are given a Node class and a List class: public class Node {    int   data;     Node next; } public class List {     Node first; } You are also given a Stack class. The following functions are available for use: public class Stack { public boolean isEmpty(){}; public void push(int n){}; public int pop(){};} Write a Java method snglyRevToStck that pushes the data found in a linked list t in reverse order into the stack...

  • Create a Java application that allows user to build a Priority Queue of Circle Elements (i.e.,...

    Create a Java application that allows user to build a Priority Queue of Circle Elements (i.e., priority based on the radius of the circle). The application must be menu controlled similar to Project 4 and provide the following. Allow insertion of a "Circle" object/structure in the Priority Queue data structures. Allow display of all elements from Priority Queue data structure by Invoking a method/function "DisplayPriorityQueue" (uses "DeQueue" method). Allow for deletion of the Queue This is what I have so...

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