0% found this document useful (0 votes)
28 views5 pages

Palindrome Programme

This document contains code for a Queue class that can be used to check if a string is a palindrome. The Queue class implements methods like insert, remove, peek and more to add and remove characters from the queue. It also uses a stack to simultaneously add and remove characters to check for palindromes.

Uploaded by

John Boy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Palindrome Programme

This document contains code for a Queue class that can be used to check if a string is a palindrome. The Queue class implements methods like insert, remove, peek and more to add and remove characters from the queue. It also uses a stack to simultaneously add and remove characters to check for palindromes.

Uploaded by

John Boy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

import java.util.

Scanner;

public class Queue1 {

private int maxSize;

private char[] queueArray;

private char[] stackArray;

private int front;

private int rear;

private int top;

private int currentSize;

public Queue1(int size){

this.maxSize = size;

this.queueArray = new char[size];

this.stackArray = new char[size];

front = 0;

rear = -1;

currentSize = 0;

top = 0;

public void insert(char item){

if(isQueueFull()){

System.out.println("Queue is full!");

return;
}

if(rear == maxSize - 1){

rear = -1;

queueArray[++rear] = item;

currentSize++;

public void Stackpush(char item1){

stackArray[top] = item1;

top++;

public char remove(){

if(isQueueEmpty()){

throw new RuntimeException("Queue is empty");

char temp = queueArray[front++];

if(front == maxSize){

front = 0;

}
currentSize--;

return temp;

public char Stackpop(){

top--;

return stackArray[top];

public int peek(){

return queueArray[front];

public boolean isQueueFull(){

return (maxSize == currentSize);

public boolean isQueueEmpty(){

return (currentSize == 0);

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter your String: ");

String input = sc.nextLine();


int count=0;

for(int i = 0; i < input.length(); i++)

// if(input.charAt(i) != ' ')

count++;

Queue1 queue = new Queue1(count);

for(int j = 0; j < input.length(); j++) {

queue.insert(input.charAt(j));

queue.Stackpush(input.charAt(j));

boolean isPalindrome=true;

while (!queue.isQueueEmpty()) {

if (queue.remove() == queue.Stackpop()) {

continue;

} else {

isPalindrome=false;

break;

if (!isPalindrome) {

System.out.println("Not a Palindrome");
} else {

System.out.println("Palindrome");

You might also like