(JAVA)Define a method getFrequency(anEntry) for the Linked List implementation of stack ADT. The method returns the number of occurrences of anEntry in the stack.
import java.util.LinkedList;
class MyStack{
LinkedList<Integer> stack;
MyStack(){
stack = new
LinkedList();
}
public void push(Integer e){
stack.push(e);
}
public Integer pop(){
return
stack.pop();
}
public Integer peek(){
return
stack.peek();
}
public int frequency(int element){
int count = 0;
for(Integer x :
stack){
if(x==element){
count++;
}
}
return count;
}
@Override
public String toString(){
return
stack.toString();
}
}
class Main {
public static void main(String[] args) {
MyStack stack = new
MyStack();
stack.push(2);
stack.push(2);
stack.push(3);
stack.push(2);
stack.push(5);
System.out.println("Stack is "+stack);
System.out.println(stack.frequency(2));
}
}
OUTPUT :

(JAVA)Define a method getFrequency(anEntry) for the Linked List implementation of stack ADT. The method returns the...
The following is a Java method that is part of a Linked List based Stack implementation: void foo() { if (front==null) return; LinkedNode c = front; int a = count/2; for (int i=1; i<a; i++) c = c.next; c.next = null; } Describe what this method is doing at a high level. Removing the last element Removing the upper half of elements in the Stack. Removing the first element Removing the bottom half of elements in the Stack.
Write a JAVA contains method for a linked implementation of a sorted list. #This method is written from the implementation perspective, meaning it would go inside of the LinkedSortedList class. This means we have access to firstNode and numberOfEntries. #write an efficient solution. This will involve directly accessing the linked structure rather than only invoking existing methods. You can assume T is Comparable. #The method header is: public boolean contains(T anEntry)
Name: Each question is worth 1 point. 20 1. In a linked-chain implementation of a Stack ADT, the performance of pushing an entry onto the stack is a. 0(2) b. О(n) С. 0(r) Answer: What is the entry returned by the peek method after the following stack operations. push(A), push(R), pop0. push(D), popO, push(L), pop0, pushJ), push(S), pop). pop 2. b.S c. L d. D Answer: n an efficient array-based chain implementation of a Stack ADT, the entry peek returns...
Assume you are working with a stack implementation of the linked list definition pasted below, write a member method “pop”. The method should return a value (in the “popped” node). Assume the existence of the node references called “TheStack” and “Top”. These references point to the start (or bottom) and top of the stack (or back of the list). ------- Definition: class node { boolean data; node link; }
When using a linked list for stack implementation, we use the first Node as the top entry of stack. Explain, in this linked list implementation, how we add and how we remove an entry from a stack. Use linked nodes diagrams to save your time. add remove
6. In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is full? O(1) O(n) O(n log n) O(n2) Undefined 7. In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is not full? O(1) O(n) O(n log n) O(n2) Undefined 8. The efficiency for recursively traversing a chain of linked nodes is O(1) O(n) O(n2) it cannot be proven...
How do you implement a stack using a singly linked list in Java? Can you make it a simple implementation with just push and pop methods.
Please answer in Java code Specify the list-based implementation for a enqueue() and dequeue() method of the Queue ADT.
please explain in clear words: Does the Stack ADT indicate whether to use an array or linked list implementation? Why or why not?
write the java code to convert a linked list of integers, to a stack of integers. thus your code will traverse the linked listand populate the stsck. linked list 1->2->3. becomes stack 3 First Last 2 1