Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 0.48 KB | None | 0 0
  1. ispalindrome(x:INTEGER):BOOLEAN is
  2.             local
  3.                 forward : STRING
  4.                 reverse : STRING
  5.                 i1: INTEGER
  6.                 i2: INTEGER
  7.             do
  8.                 forward:=x.to_string
  9.                 reverse:=copy(forward)
  10.                
  11.                 from
  12.                     i1 := 1
  13.                     i2 := reverse.count
  14.                 until
  15.                     i1 >= i2
  16.                 loop
  17.                     reverse.swap(i1, i2)
  18.                     i1 := i1 + 1
  19.                     i2 := i2 - 1
  20.                 end
  21.                 if forward.is_equal(reverse) then       -- compare if they are the same
  22.                     Result := True
  23.                 else
  24.                     Result := False
  25.                 end    
  26.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement