Create a Stack class based on java.util.LinkedList class. Your
Stack class should have a push(), pop(), peek(), and isEmpy()
methods.
Create a new Java Application that has the following methods.
Write a method reverseChar() to print a sentence in reverse order. Use a Stack to reverse each character. Example: if the user enters a sentence “ABC DEFG”, the program will display “GFED CBA”
Write a method reverseWord() to print a sentence reverse order. Use a Stack to reverse each word. Example: If the user enters a sentence "Live and Let Live" the program will display "Live Let and Live"
Write a method to randomly generate a number of elements between two given values and save them in a stack.
Write a method to print a stack (10 elements per line). The original stack should remain as is after the print.
Write a method to return the number of elements on the stack (without changing the stack).
Write a method to search for a value in a stack. The stack should remain the same after the search is finished.
Write a method to print the second element of the stack and leave the original stack unchanged
Write a method to count the number of elements in a stack that are larger than a given value and leave the original stack unchanged.
Write a method peekLowestElement() to return the smallest element. The original stack should remain unchanged.
10. Write a method peekHighestElement() to return the largest element. The original stack should remain unchanged.
11. Write a method to return the inverse a stack. The original
stack should remain unchanged.
12. Write a method to make a copy of a stack into another stack and
return it. The original stack should remain
unchanged.
In the main method test all your methods including the following cases:
Create 2 Stacks S1, S2
Insert 20 integers between 20 and 60 (do not insert duplicates) into S1
Insert 30 integers between 10 and 80 (do not insert duplicates) into S2.
Test all your methods using S1 and S2
I already wrote the code for the BOLD one I'm stuck in 9 , 10 ,11 ,12
|
import java.util.*; class Main // Constructor to initialize stack // Utility function to add an element x in the
stack // System.out.println("Inserting " +
x); // Utility function to pop top element from the
stack System.out.println("Removing " + peek()); // decrease stack size by 1 and
(optionally) return the popped element // Utility function to return top element in a
stack return -1; return -1; public Main stack_copy(Main Object){ //This function returns a
copied stack of stack object passed to it // Utility function to check if the stack is full
or not public static void main (String[] args) |
I have copied and reversed the stack for you in the main function you can try it for stack1 too.
Also Since you have to make a Stack class please make sure to replace the Main with Stack everywhere in the code.
Create a Stack class based on java.util.LinkedList class. Your Stack class should have a push(), pop(),...
Create a Stack class based on java.util.LinkedList class. Your Stack class should have a push(), pop(), peek(), and isEmpy() methods. Create a new Java Application that has the following methods. Write a method reverseChar() to print a sentence in reverse order. Use a Stack to reverse each character. Example: if the user enters a sentence “ABC DEFG”, the program will display “GFED CBA” Write a method reverseWord() to print a sentence reverse order. Use a Stack to reverse each word....
java Create a Queue class based on java.util.LinkedList class. Your Queue class should have an enqueue(), dequeue(), peek(), and isEmpy() methods. Create a new Java Application that has the following methods: A method to randomly generate a number of elements between two given values and save them in a queue A method to print a queue (10 elements per line). The original queue should remain as is after the print A method to return the number of elements on the...
Create a new Java Application that test MyStack by having the following methods in main class: 1. A method to generate a number of element between two given values and save them in a stack 2. A method to print a stack (10 elements per line). The original stack should remain as is after the print 3. A method to exchange the first element and the last element in a stack 4. A Boolean method to search for a value...
Create a new Java Application that test MyStack by having the following methods in main class: 1. A method to generate a number of element between two given values and save them in a stack 2. A method to print a stack (10 elements per line). The original stack should remain as is after the print 3. A method to exchange the first element and the last element in a stack 4. A Boolean method to search for a value...
using: class MyQueue<T> { private java.util.LinkedList<T> list; public MyQueue() { list = new java.util.LinkedList<T>(); } public void enqueue(T data) { list.add(data); } public T dequeue() { return list.remove(0); } public T peek() { return list.get(0); } public int size() { return list.size(); } public boolean isEmpty() { return list.isEmpty(); } } class MyQueueTest { public static void main(String[] args) { MyQueue<Integer> queue = new MyQueue<Integer>(); queue.enqueue(3); queue.enqueue(2); queue.enqueue(7); queue.enqueue(1); while (!queue.isEmpty()) { System.out.println(queue.dequeue()); } } } please solve the following:...
) Consider Java's Stack class, and its five standard stack operations: push, pop, peek, isEmpty, and clear. Complete the two unfinished methods. Do not modify any other parts of the class. // Looks at the top two elements of the stack, and removes and returns the larger // of the two elements from the stack, returning the other element to the stack. // For example, if the stack, from the top, is 8 10 7 2...
Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a string),...
C++ Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a...
Problem 2: based on java.util.LinkedList class, create MyStack class that should have the methods: push(), pop(), peek(), size(), isEmpty(). my linkedlist class is: public class Lab8_problem1 { private Node head, tail; private int size; public Lab8_problem1() { this.head = null; this.tail = null; this.size = 0; } //Insert a node at specifc Location public void insertAt(int value, int index) { Node newNode = new Node(); newNode.data = value; if(head == null){ head = newNode; tail = newNode; head.next...
On java create the following:
please solve it complete or don't since it considered as part of
problem 1 not even the whole question.
The main method that does:
Create 2 stacks s1 and s2
Insert 23 integers between 20 and 60 (do not insert duplicates)
into s1
Insert 35 integers between 10 and 80 (do not insert duplicates)
into s2.
Give the user the choice which methods (2-7) to call and option
to exit
LinkedList<Integer> LL = new LinkedList<Integer>)...