| | |
Trying To Create a Palindrome Programme
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 10
Reputation:
Solved Threads: 0
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
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.
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)
PROGRAM Palindrome (input, output); TYPE pQueue = ^tQueue; tQueue = RECORD prev : pQueue; data : String [80]; next : pQueue; END; VAR Front, Rear, Temp : pQueue; i : String [80]; Choice : CHAR; Count : INTEGER; Palid : BOOLEAN; {***************************************************************************} PROCEDURE add; BEGIN NEW (Temp); Temp^.data := i; Temp^.next := nil; IF Front = nil THEN Front := Temp ELSE Rear^.next := Temp; Rear := Temp; END; {***************************************************************************} PROCEDURE view; BEGIN Temp := Front; WHILE Temp <> Nil DO BEGIN WRITELN (Temp^.data); Temp := Temp^.next; END; END; {***************************************************************************} PROCEDURE destroy; BEGIN Temp := Front; WHILE Temp <> nil DO BEGIN Temp := Temp^.next; DISPOSE (Front); Front := Temp; END; END; {***************************************************************************} PROCEDURE Entry; BEGIN Front := Nil; WRITELN ('Please Enter A Word'); READLN (i); add; view; destroy; END; {***************************************************************************} BEGIN Count := 0; WRITELN ('Would You Like To Enter A Word?'); READLN (Choice); WHILE (Choice = 'Y') OR (Choice = 'y') DO BEGIN IF (Choice = 'Y') OR (Choice = 'y') THEN Entry; WRITELN ('Would You Like To Enter Another Word?'); READLN (Choice); Count := Count + 1; END; WRITELN (Count); 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.
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
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
Loren Soth
Crimson K. Software _________________________________________________________________ Crimson K. Blog
Hi,
Do you need to create Palindromes or check wether the word entered by user is a palindrom ?
Loren Soth
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
Loren Soth
Crimson K. Software _________________________________________________________________ Crimson K. Blog
with char arrays, it could be:
just take the same principle with memory addresses, but bear in mind that only works if the word has an even number of characters.
Pascal and Delphi Syntax (Toggle Plain Text)
ispalindrome := true; for i := 0 to arr.length /2 do 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.
![]() |
Similar Threads
- how to create a zig zag encryption (C++)
- problem in c++ (C++)
- Multimedia Application... (Graphics and Multimedia)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: code conversion from C++ to delphi
- Next Thread: Convert to hex
| Thread Tools | Search this Thread |






