Trying To Create a Palindrome Programme

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2006
Posts: 10
Reputation: Latent is an unknown quantity at this point 
Solved Threads: 0
Latent Latent is offline Offline
Newbie Poster

Trying To Create a Palindrome Programme

 
0
  #1
Jul 10th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 233
Reputation: Lord Soth is an unknown quantity at this point 
Solved Threads: 4
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

Re: Trying To Create a Palindrome Programme

 
0
  #2
Jul 11th, 2006
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
Best regards,
Loren Soth

Crimson K. Software _________________________________________________________________ Crimson K. Blog
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 10
Reputation: Latent is an unknown quantity at this point 
Solved Threads: 0
Latent Latent is offline Offline
Newbie Poster

Re: Trying To Create a Palindrome Programme

 
0
  #3
Jul 11th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 233
Reputation: Lord Soth is an unknown quantity at this point 
Solved Threads: 4
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

Re: Trying To Create a Palindrome Programme

 
0
  #4
Jul 11th, 2006
Hi,

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

Loren Soth
Best regards,
Loren Soth

Crimson K. Software _________________________________________________________________ Crimson K. Blog
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 10
Reputation: Latent is an unknown quantity at this point 
Solved Threads: 0
Latent Latent is offline Offline
Newbie Poster

Re: Trying To Create a Palindrome Programme

 
0
  #5
Jul 11th, 2006
I need for the program to check if the word entered is a palindrome or not.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Trying To Create a Palindrome Programme

 
0
  #6
Jul 20th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 10
Reputation: Latent is an unknown quantity at this point 
Solved Threads: 0
Latent Latent is offline Offline
Newbie Poster

Re: Trying To Create a Palindrome Programme

 
0
  #7
Jul 24th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC