Question

In: Computer Science

IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards....

IN JAVA -

[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate

[(2)] Let Q be a non-empty queue, and let S be an empty stack. Using only the stack and queue ADT functions and a single element variable X, write an algorithm to reverse the order of the elements in Q.

[(3)] Use singly linked lists to implement integers of unlimited size. Each node of the list should store one digit of the integer. You should implement addition, subtraction, multiplication, and exponentiation operations. Limit exponents to be positive integers. What is the asymptotic running time for each of your operations, expressed in terms of the number of digits for the two operands of each function?

[(4)] Implement a program that can input an expression in postfix notation and output its value.

Solutions

Expert Solution

SOLUTION -

Code for Palindrome.java

Sample Output 1

Sample Output 2

Code for Palindrome.java

import java.io.*;
import java.util.Stack;
import java.util.LinkedList; //libraries required
import java.util.Queue;
import java.util.Scanner;


public class Palindrome{


   public static boolean check_Palindrome(String str){ //method to check if the given string is palindrome or not

       Queue<Character> queue = new LinkedList<Character>(); //declaring the queue

       Stack<Character> stack = new Stack<Character>(); //declaring the stack

       Character alphabet;

       int count = 0;
  
   for (int i = 0; i < str.length(); i++){
             
           alphabet = str.charAt(i);   

           queue.add(alphabet); //add each character to the queue and the stack

           stack.push(alphabet);
          
   }
      
       while (!queue.isEmpty()){
             
           if (queue.remove()!=stack.pop()) //removal of each character from queue and stack must be same to say it's palindrome
               count++;
      
       }

       if(count==0) //if the count equal to zero then it is a palindrome
           return true;
       else
           return false;
   }


   public static void main(String[] args) {

       String str;

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter the string : "); //taking string from user

       str = sc.nextLine();

      
       if(check_Palindrome(str))
           System.out.println("True");
      
       else
           System.out.println("False");


      
   }

}

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

python question A word is a palindrome if it the same read forwards and backwards. We...
python question A word is a palindrome if it the same read forwards and backwards. We will call a word a fuzzy palindrome if it is the same read forwards and backwards, except for possible differences in case. For example, both 'tattarrattat' and 'TaTtArRAttat' are fuzzy palindromes. Define a function is_fuzzy_palindrome that returns True if and only if its argument is a fuzzy palindrome. This method may be useful: S.lower() -> str : Return a copy of the string S...
In C++: This is the problem: [(1)] A palindrome is a string that reads the same...
In C++: This is the problem: [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q...
1. A is called a palindrome if it reads the same from left and right. For...
1. A is called a palindrome if it reads the same from left and right. For instance, 13631 is a palindrome, while 435734 is not. A 6-digit number n is randomly chosen. Find the probability of the event that (a) n is a palindrome. (b) n is odd and a palindrome. (c) n is even and a palindrome.
C++: A palindrome is a string that is the same backward as it is forward. For...
C++: A palindrome is a string that is the same backward as it is forward. For example, “tot” and “otto” are rather short palindromes. Write a program that lets a user enter a string and that passes to a bool function a reference to the string. The function should return true if the string is a palindrome and false otherwise. When you do the judgment, capitalization, spaces, and punctuation should be neglected, that is, “Madam, I’m Adam” should test as...
A is called a palindrome if it reads the same from left and right. For instance,...
A is called a palindrome if it reads the same from left and right. For instance, 13631 is a palindrome, while 435734 is not. A 6-digit number n is randomly chosen. Find the probability of the event that (a) n is a palindrome. (b) n is odd and a palindrome. (c) n is even and a palindrome.
A palindrome is a word or phrase, which reads the same backward or forward. Write a...
A palindrome is a word or phrase, which reads the same backward or forward. Write a program that prompts the user for a string of characters terminated by a period and determines whether the string (without the period) is a palindrome. IMP: Assume that the input contains only letters and blanks. Assume also that the input is at most 30 characters long. Use an array of characters of size 30 to store the input! Disregard blanks when deciding if the...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it is same when read from the front and the end. For example, String “abcba” is palindrome, while “12322” is not. Write Java program to check a String object of 5 characters is palindrome or not: (a) The comparison is case sensitive (b) The comparison is case insensitive
JAVA. A palindrome is a word or a phrase that is the same when read both forward and backward.
java please. A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.Ex: If the input is:bobthe output is:bob is a palindromeEx: If the input is:bobbythe output is:bobby is not a palindromeHint: Start by removing spaces. Then check if a string is equivalent to it's reverse.Hint: Start by just handling single-word...
Write a Java console application that reads a string for a date in the U.S. format...
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY  For example, if the input is 02/08/2017, your program should output 08.02.2017
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT