Explore BrainMass
Share

Use a stack to reverse the contents of a file

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

File Reverser
Write a program that opens a text file and reads its contents into a stack of characters. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file.

Requirement: stack class implementation (with push/pop) to accept input file of any size

Hint: Use dynamic stack implementation to accept input file with any size

you can use/modify LinkedList class in stack implementation

© BrainMass Inc. brainmass.com October 25, 2018, 1:53 am ad1c9bdddf
https://brainmass.com/computer-science/linked-lists/use-a-stack-to-reverse-the-contents-of-a-file-278712

Attachments

Solution Preview

The first thing that needs to be done is that the LinkedList that is
included with the posting needs to be changed to store characters
instead of integers. This primarily requires changing the type of the
data field in the Node class. We also need to change the DeleteAtHead
and DeleteAtTail methods so that they return the deleted ...

Solution Summary

This solutions shows how to reverse the characters in a file using a stack. It is a good example of how a stack is implemented and used.

$2.19
See Also This Related BrainMass Solution

Test the stack class by determining if the given strings have matching open and closing () and/or {} and/or []. Write the code to test the queue class by determining if the given strings are char-by-char palindromes.

Please help me in writing the code to test the stack class, and enhancing and testing the queue class.

1. Test the stack class by determining if the following strings have matching open and closing () and/or {} and/or [] :
()
[](){}
[{()}]
[[))
{()[()]}

The fourth one is the only one that should not have matching pairs.

2. Please complete the Queue class including following functions:
enqueue
dequeue
front
size

Write the code to test the queue class by determining if the following strings are char-by-char palindromes:
ABCDEDCBA
NOTAPALINDROME
ISPALINILAPASI
2A3MEAS
ATOYOTA
(({}[][]{}((

Please refer to the attached files to use for the input.

View Full Posting Details