mod merge_sort; mod quick_sort; use crate::quick_sort::quick_sort; use crate::merge_sort::merge_sort_inversions; use std::fs::File; use std::io; use std::io::{BufRead, BufReader, Error, ErrorKind}; use std::vec::Vec; fn read_to_vector(path: &str) -> Result, io::Error> { let file = File::open(path)?; let br = BufReader::new(file); let mut v = Vec::new(); for line in br.lines() { let line = line?; let n = line .trim() .parse() .map_err(|e| Error::new(ErrorKind::InvalidData, e))?; v.push(n); } Ok(v) } #[allow(dead_code)] fn c1a2() { let vec = read_to_vector("data/course_1_assignment_2.txt").unwrap(); let (_sorted, inversions) = merge_sort_inversions(vec); println!("course 1 assignment 2: {:?}", inversions); } fn c1a3() { // let mut vec = read_to_vector("data/course_1_assignment_3.txt").unwrap(); let mut vec = vec![2, 20, 1, 15, 3, 11, 13, 6, 16, 10, 19, 5, 4, 9, 8, 14, 18, 17, 7, 12]; let mut comp_acc: usize = 0; quick_sort(&mut vec, &mut comp_acc); // println!("{:?}", vec); println!("{:?}", comp_acc); println!("{:?}", 3/2); /* 1: 162085 2: 164123 3: ? */ } fn main() { //c1a2(); c1a3(); }