Start to implement assignment 4
This commit is contained in:
parent
f76f570d8b
commit
47e5fec4bd
@ -2,6 +2,7 @@ mod merge_sort;
|
|||||||
mod quick_sort;
|
mod quick_sort;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
use crate::util::read_to_graph;
|
||||||
use crate::util::read_to_vector;
|
use crate::util::read_to_vector;
|
||||||
use crate::quick_sort::quick_sort;
|
use crate::quick_sort::quick_sort;
|
||||||
use crate::merge_sort::merge_sort_inversions;
|
use crate::merge_sort::merge_sort_inversions;
|
||||||
@ -27,7 +28,8 @@ fn c1a3() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn c1a4() {
|
fn c1a4() {
|
||||||
println!("Here we go again!");
|
let g = read_to_graph("data/course_1_assignment_4.txt").unwrap();
|
||||||
|
println!("{:?}", g);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
4
src/min_cut.rs
Normal file
4
src/min_cut.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
20
src/util.rs
20
src/util.rs
@ -3,6 +3,14 @@ use std::io;
|
|||||||
use std::io::{BufRead, BufReader, Error, ErrorKind};
|
use std::io::{BufRead, BufReader, Error, ErrorKind};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Graph {
|
||||||
|
nodes: Vec<u32>,
|
||||||
|
edges: Vec<(u32, u32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
|
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
|
||||||
let file = File::open(path)?;
|
let file = File::open(path)?;
|
||||||
let br = BufReader::new(file);
|
let br = BufReader::new(file);
|
||||||
@ -19,3 +27,15 @@ pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn read_to_graph(path: &str) -> Result<Graph, io::Error> {
|
||||||
|
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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user