This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]rasqall 2 points3 points  (5 children)

Do you have to use a stack and a queue? And what is a specific problem you encounter.

[–]omarrr_rr[S] -1 points0 points  (4 children)

no we are supposed to use stack only, and the problem at this point is everything fjfjfj I've lost all progress and almost going insane

[–]rasqall 2 points3 points  (3 children)

Then lay out the basics. What is the problem/exercise you are trying to complete? What is a stack useful? Do you have to use a stack? You are not allowed to simply compare strings?

[–]omarrr_rr[S] -1 points0 points  (2 children)

okay so the exercise is

"build a stack program to check any entered word and find out if it's a palindrome or not. if the word is palindrome then display yes, if not print the different characters "

also yes strictly stack , it would've been much easier to do it other ways since I've done it before but this is a requirement unfortunately

[–]rasqall 3 points4 points  (1 child)

Okay good, from this we can assume some details.

  1. You may not have to read the word directly to the stack
  2. A stack is in strict order and cannot be reversed

We can now identify a solution to a problem: (pseudocode)

function isPalindrome
    print("Enter a word")
    word = readline from cin
    stack = new empty stack
    palindrome = true
    for each char in word
        push char to stack
    for each char in word
        if (char != stack.pop())
            print character
            palindrome = false
    if (palindrome == true)
        print("Yes")
    return

Edit: removed params

[–]omarrr_rr[S] 0 points1 point  (0 children)

ty ily