Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/* A palindrome is a string that reads the same way forwards and backwards. Write a Java method method that uses an explicit stack to
/* A palindrome is a string that reads the same way forwards and backwards. Write a Java method method that uses an explicit stack to check if a string is a palindrome. This can be implemented with just a loop, however you will not receive credit if you do not use a stack. Test is included in PalendromTest.java. */ public class Palendrome { public boolean isPalendrome(String s) { // TODO: Implement me return false; } }
------------------------
/* Implement a `pushAll` method for a stack that appends the contents of a stack onto `this` stack. The elements transfered must maintain their original ordering. Thus, this is *not* as simple as popping off one stack as you push onto the other in a loop. A test is included in IntStackTest.java. */ public class IntStack { static class Node { int data; Node next; Node(int data, Node next) { this.data = data; this.next = next; } } Node top; public void push(int i) { this.top = new Node(i, this.top); } public int pop() { int result = this.top.data; this.top = this.top.next; return result; } public boolean isEmpty() { return this.top == null; } public void pushAll(IntStack other) { // TODO: Finish implementing } }
-----------------------
/* Below is a recursive definition of a simple algorithm for computing the greatest common denominator of two integers. Translate it into a tail-recursive Java method (`gcdRec`) and then rewrite that recursive method into an iterative method (`gcdIter`). ``` gcd(a, b) = if a == 0, then b else gcd(b % a, a) ``` */ public class Gcd { public static int gcdRec(int a, int b) { // TODO: Implement me return 0; } public static int gcdIterative(int a, int b) { // TODO: Implement me return 0; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started