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

2. Palindromes A palindrome is a word that reads the same forwards and backwards. For example,...
2. Palindromes A palindrome is a word that reads the same forwards and backwards. For example, \aibohphobia" (the irrational fear of palindromes) is a word that reads the same forwards and backwards. Write a function called isPalindrome() that accepts a string as a parameter and returns True if the string is a palindrome, False otherwise. Using the function you created, write a program Python home work Python
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...
making a python code for this: A palindrome is a sequence that reads the same backwards...
making a python code for this: A palindrome is a sequence that reads the same backwards as forwards. Numbers can also be palindromes if we consider their digits as a sequence, for example 12121 and 8228 are palindromes. We can find palindromes from an initial seed number using the reverse and add method: choose a number, reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number...
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...
A palindrome is a string that reads the same forward and backward, i.e., the letters are...
A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right.      Examples: radar à is a palindrome Able was I ere I saw Elba à is a palindrome good à not a palindrome Write a java program to read a line of text and tell if the line is a palindrome. Use a stack to read each non-blank character...
Foundation of Computer Science A palindrome is a string that reads the same forward and backward....
Foundation of Computer Science A palindrome is a string that reads the same forward and backward. 1. Describe an algorithm that determines whether a string of n characters is a palindrome. 2. Write its corresponding program using your favorite programming language.
(Palindrome number - A number is a palindrome if it reads the same from right to...
(Palindrome number - A number is a palindrome if it reads the same from right to left and from left to right, for example 676 is a palindrome number) Write a program that prompts the user to enter a three-digit integer number and determines whether it is a palindrome number or not In Java Please
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT