From 47e5fec4bd02f8ad4559f2a032886871b10281a3 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Fri, 27 Nov 2020 15:23:14 -0500 Subject: [PATCH] Start to implement assignment 4 --- src/main.rs | 4 +++- src/min_cut.rs | 4 ++++ src/util.rs | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/min_cut.rs diff --git a/src/main.rs b/src/main.rs index 65a950d..3b6a633 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod merge_sort; mod quick_sort; mod util; +use crate::util::read_to_graph; use crate::util::read_to_vector; use crate::quick_sort::quick_sort; use crate::merge_sort::merge_sort_inversions; @@ -27,7 +28,8 @@ fn c1a3() { } fn c1a4() { - println!("Here we go again!"); + let g = read_to_graph("data/course_1_assignment_4.txt").unwrap(); + println!("{:?}", g); } fn main() { diff --git a/src/min_cut.rs b/src/min_cut.rs new file mode 100644 index 0000000..fd40910 --- /dev/null +++ b/src/min_cut.rs @@ -0,0 +1,4 @@ + + + + diff --git a/src/util.rs b/src/util.rs index f93b28e..b4c5bfc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -3,6 +3,14 @@ use std::io; use std::io::{BufRead, BufReader, Error, ErrorKind}; use std::vec::Vec; + +#[derive(Debug)] +pub struct Graph { + nodes: Vec, + edges: Vec<(u32, u32)>, +} + + pub fn read_to_vector(path: &str) -> Result, io::Error> { let file = File::open(path)?; let br = BufReader::new(file); @@ -19,3 +27,15 @@ pub fn read_to_vector(path: &str) -> Result, io::Error> { } +pub fn read_to_graph(path: &str) -> Result { + let mut g = Graph { nodes: vec![], edges: vec![] }; + let file = File::open(path)?; + let br = BufReader::new(file); + + for line in br.lines() { + let line = line?; + println!("{:?}", line); + } + + Ok(g) +} \ No newline at end of file