Skip to content

Commit

Permalink
Adding some print messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jlechem committed Sep 22, 2024
1 parent dd39998 commit 2b57eb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions filesort-rs/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1
2
3
4
44
5
6
7
8
9
8 changes: 6 additions & 2 deletions filesort-rs/src/line_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ impl FileSort for LineSort {
fn read(&mut self) {
let file = File::open(&self.input_file).expect("input file doesn't exist");

let buffer = BufReader::new(file);
let buffer: BufReader<File> = BufReader::new(file);

for line in buffer.lines() {
self.lines.push(line.unwrap_or_default());
}
}

fn write(&mut self) {
println!("{0}", self.output_file);
let mut file: File = File::create(&self.output_file).expect("Unable to create output file {0}");

for line in &self.lines {
write!(file,"{}\n", line).expect("Unable to write data to file.")
}
}

fn sort(&mut self) {
Expand Down
11 changes: 11 additions & 0 deletions filesort-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ fn main() {
args.line {
let mut linesort: LineSort = LineSort::new(args.input_file, args.output_file, args.descending);

println!("Filesort start\n");
println!("Reading file data\n");

linesort.read();

println!("Soritng data\n");

linesort.sort();

println!("Writing file data\n");

linesort.write();

println!("Filesort complete\n");
}
else {
let mut wordsort: WordSort = WordSort::new(args.input_file, args.output_file, args.descending);
Expand Down

0 comments on commit 2b57eb2

Please sign in to comment.