Palindromes

Report a typo

Here's Find a Palindrome, one of the classic tasks of computer science. A palindrome is a word or sentence with the same order of characters in both directions (for example, the word pop is a palindrome, but the word push is not; it will be the hsup word in the other direction). Try to solve it using stack and queue.

Note that the Stack and Queue structs are already declared and set up to store rune values for this task.

Don't think about how to read the input and return an answer, focus on the task. If you are stuck, welcome to the HINT section.

  1. Tip: fill the Stack structure and the Queue structure with a Push function;
  2. Tip: start to Pop values from structures;
  3. Tip: the Stack will get values from the end of the storage; the Queue will get from the start;
  4. Tip: if one of the structures returns an error, it means chars is over, and the word is a palindrome (structures have the same size);
  5. Tip: if at least one of the pairs of characters is not equal, so the word is not a palindrome.

Sample Input 1:

tenet

Sample Output 1:

Palindrome

Sample Input 2:

do

Sample Output 2:

Not palindrome
Write a program in Go
package main

import "fmt"

func main() {
var word string
// the Stack and Queue structs are hidden but already declared
var stackSolver Stack
var queueSolver Queue

fmt.Scan(&word)

for _, char := range word {
?
?
}

for {
?
?

if ? {
fmt.Println("Palindrome")
break
}

if ? {
fmt.Println("Not palindrome")
break
}
}
}
___

Create a free account to access the full topic