Computer Science – 10.3 Files | e-Consult
10.3 Files (1 questions)
Login to see all questions.
Click on a question to view the answer
Algorithm: Reverse File Lines
- Start
- Open the text file for reading.
- Create an empty list called
fileLines. - Read the file line by line:
- While there are more lines to read:
- Read the next line from the file.
- Append the line to
fileLines.
- While there are more lines to read:
- Create a new empty list called
reversedLines. - For each line in
fileLines:- Append the line to the beginning of
reversedLines.
- Append the line to the beginning of
- Print the contents of
reversedLines, with each line on a new line. - Close the text file.
- End