Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

data structures and algorithms in java Question 4 (4 marks) Consider the followi

ID: 3711311 • Letter: D

Question

data structures and algorithms in java

Question 4 (4 marks) Consider the following class Arraystack: class Arraystack ( private intti data; private int t -1; public ArrayStack(int capacity) () public int size) public boolean isEmpty public void push (int e) () public int top ( public int pop () public String tostring) h Write a method removeoccurences ( N. It should remove all occurrences of N from St, the stack should have the remaining elements that takes as parameters a stack St and a value in their original order.

Explanation / Answer

public static void removeOccurences(ArrayStack st, int n) { ArrayStack temp = new ArrayStack(st.size()); while (!st.isEmpty()) { temp.push(st.pop()); } int num; while (!temp.isEmpty()) { num = temp.pop(); if(num != n) { st.push(num); } } }