944,193 Members | Top Members by Rank

Ad:
Jul 10th, 2006
0

Trying To Create a Palindrome Programme

Expand Post »
Hello everyone,

I have to create a Palindrome Programme in Pascal using Pointers and Queues.

A Palindrome is a word which when spelt backwards or forward if the same ex RACECAR or RADAR.

I am having a problem actually creating the Palindrome Part of the Code.

Thus Far, this is what I have

Pascal and Delphi Syntax (Toggle Plain Text)
  1.  
  2. PROGRAM Palindrome (input, output);
  3.  
  4. TYPE
  5.  
  6. pQueue = ^tQueue;
  7.  
  8. tQueue = RECORD
  9.  
  10. prev : pQueue;
  11.  
  12. data : String [80];
  13.  
  14. next : pQueue;
  15.  
  16. END;
  17.  
  18. VAR
  19.  
  20. Front, Rear, Temp : pQueue;
  21.  
  22. i : String [80];
  23.  
  24. Choice : CHAR;
  25.  
  26. Count : INTEGER;
  27.  
  28. Palid : BOOLEAN;
  29.  
  30. {***************************************************************************}
  31.  
  32. PROCEDURE add;
  33.  
  34. BEGIN
  35.  
  36. NEW (Temp);
  37.  
  38. Temp^.data := i;
  39.  
  40. Temp^.next := nil;
  41.  
  42. IF Front = nil THEN
  43.  
  44. Front := Temp
  45.  
  46. ELSE Rear^.next := Temp;
  47.  
  48. Rear := Temp;
  49.  
  50. END;
  51.  
  52. {***************************************************************************}
  53.  
  54. PROCEDURE view;
  55.  
  56. BEGIN
  57.  
  58. Temp := Front;
  59.  
  60. WHILE Temp <> Nil DO
  61.  
  62. BEGIN
  63.  
  64. WRITELN (Temp^.data);
  65.  
  66. Temp := Temp^.next;
  67.  
  68. END;
  69.  
  70. END;
  71. {***************************************************************************}
  72. PROCEDURE destroy;
  73.  
  74. BEGIN
  75.  
  76. Temp := Front;
  77.  
  78. WHILE Temp <> nil DO
  79.  
  80. BEGIN
  81.  
  82. Temp := Temp^.next;
  83.  
  84. DISPOSE (Front);
  85.  
  86. Front := Temp;
  87.  
  88. END;
  89.  
  90. END;
  91. {***************************************************************************}
  92.  
  93. PROCEDURE Entry;
  94.  
  95. BEGIN
  96.  
  97. Front := Nil;
  98.  
  99. WRITELN ('Please Enter A Word');
  100.  
  101. READLN (i);
  102.  
  103. add;
  104.  
  105. view;
  106.  
  107. destroy;
  108.  
  109. END;
  110.  
  111. {***************************************************************************}
  112.  
  113. BEGIN
  114.  
  115. Count := 0;
  116.  
  117. WRITELN ('Would You Like To Enter A Word?');
  118.  
  119. READLN (Choice);
  120.  
  121. WHILE (Choice = 'Y') OR (Choice = 'y') DO
  122.  
  123. BEGIN
  124.  
  125. IF (Choice = 'Y') OR (Choice = 'y') THEN
  126.  
  127. Entry;
  128.  
  129. WRITELN ('Would You Like To Enter Another Word?');
  130.  
  131. READLN (Choice);
  132.  
  133. Count := Count + 1;
  134.  
  135. END;
  136.  
  137. WRITELN (Count);
  138.  
  139. END.

I am having Problems creating the Palindrome Part. Can anyone help me out here?

I am not allowed to use arrays. Just Queues and Pointers.

Thanking you in adavnce for your assistance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latent is offline Offline
10 posts
since Mar 2006
Jul 11th, 2006
0

Re: Trying To Create a Palindrome Programme

Hi,

Ths last " IF (Choice = 'Y') OR (Choice = 'y') THEN " is unnecessary, the while loop's conditional takes care of that. You seem to have implemented the queue correctly but why is you TQueue's Data is a String of length 80 ? If your code is to check whether a given word is a palindrome then the data should be a single char and the whole queue should contain the entered word char by char; then to check you should compare the chars using two pointers one going forward from FRONT and other going backward from REAR at the same time, if all chars are equal than this is a palindrome.

Loren Soth
Reputation Points: 28
Solved Threads: 4
Posting Whiz in Training
Lord Soth is offline Offline
233 posts
since Mar 2006
Jul 11th, 2006
0

Re: Trying To Create a Palindrome Programme

Lord Soth, Thanks for replying and helping me.

However, can you show me a sample code of how to create the Palindrome? I have been trying and having some problems.

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latent is offline Offline
10 posts
since Mar 2006
Jul 11th, 2006
0

Re: Trying To Create a Palindrome Programme

Hi,

Do you need to create Palindromes or check wether the word entered by user is a palindrom ?

Loren Soth
Reputation Points: 28
Solved Threads: 4
Posting Whiz in Training
Lord Soth is offline Offline
233 posts
since Mar 2006
Jul 11th, 2006
0

Re: Trying To Create a Palindrome Programme

I need for the program to check if the word entered is a palindrome or not.

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latent is offline Offline
10 posts
since Mar 2006
Jul 20th, 2006
0

Re: Trying To Create a Palindrome Programme

with char arrays, it could be:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. ispalindrome := true;
  2.  
  3. for i := 0 to arr.length /2 do
  4. ispalindrome := ispalindrome and (arr[i] == arr[arr.length - i]);

just take the same principle with memory addresses, but bear in mind that only works if the word has an even number of characters.
Last edited by MattEvans; Jul 20th, 2006 at 8:58 pm.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Jul 24th, 2006
0

Re: Trying To Create a Palindrome Programme

Matt Evans and Lord Soth, thanks for all your advice and assistance. I was able able to get the program working but it had a couple of bugs. Still, your advice and help allowed me to be on the right track, thanks again.

I will post the code I came up with soon to show you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latent is offline Offline
10 posts
since Mar 2006
Oct 27th, 2011
-1
Re: Trying To Create a Palindrome Programme
function palindromcheck (s:string) :bool;
var l,i:integer;
begin
l:=Length(s);
for i:=0 to (l div 2) do begin
if comparetext(s[i+1], s[l-i])<>0 then Result:=false;
end;

end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if palindromcheck(Edit1.Text) = true then begin
label1.Caption := 'schönes Polinom';
end
else begin
label1.Caption := 'kein schönes Polinom';
end;
end;

hf&gl
Reputation Points: 7
Solved Threads: 0
Newbie Poster
00beda is offline Offline
1 posts
since Oct 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Delphi Code help with the "Randomized Walk: Ant"
Next Thread in Pascal and Delphi Forum Timeline: Working with TImageLists help! please!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC