Pallendrom string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GAWRAHUL
    New Member
    • Sep 2010
    • 1

    Pallendrom string

    program in c for to check whether the string is pallendrom or not using stack.h file and stack
    Last edited by Nepomuk; Sep 9 '10, 12:33 PM. Reason: Please use [CODE] tags around code, not around normal text
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Hi!

    This sounds like homework... what have you done so far? We won't give you a solution but we'll be happy to help you find one.

    Greetings,
    Nepomuk

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      If the palindrome was one word (a string of characters) you could make one pointer point to the first letter and a second pointer point to the last letter and compare *p1 with *p2 from within the body of a for loop. If they are == increment p1(++) and decrement p2(--) and continue to compare for equality until the loop condition (< length of the word/2)is reached or the comparison fails. The same principle could be applied to a sentence.

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        This will work, but won't be accepted because it doesn't use (! turbo-c header) stack.h . The solution that may pass is to push the entire string into the stack and then pop it back comparing to it again, so that the first character in the string is compared to the last pushed ( = first popped ) into the stack.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          @newb16
          Yes... I read 'not' in the wrong context.
          But in any case I could not have suggested a way of doing it using a stack so I learnt something.

          Comment

          Working...