Question: /* 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!