Clean up and get ready for two sum assignment

This commit is contained in:
2020-12-12 10:19:24 -05:00
parent e9d0620ab5
commit 99ef6d4d1c
10 changed files with 49 additions and 8 deletions

View File

@@ -91,9 +91,9 @@ impl<T: std::cmp::PartialOrd> MinHeap<T> {
}
}
pub fn heap(v: &Vec<i32>) -> i32 {
let mut hl: MinHeap<i32> = MinHeap::new();
let mut hh: MinHeap<i32> = MinHeap::new();
pub fn heap(v: &Vec<i64>) -> i64 {
let mut hl: MinHeap<i64> = MinHeap::new();
let mut hh: MinHeap<i64> = MinHeap::new();
let mut iter = v.into_iter();
let mut current_median = *iter.next().unwrap();

View File

@@ -5,15 +5,16 @@ mod min_cut;
mod quick_sort;
mod ssc;
mod util;
mod two_sum;
use std::cmp::min;
use crate::dijkstra::dijkstra;
use crate::heap::heap;
use crate::merge_sort::merge_sort_inversions;
use crate::min_cut::min_cut;
use crate::quick_sort::quick_sort;
use crate::ssc::ssc;
use crate::two_sum::find_two_sums;
#[allow(dead_code)]
fn c1a2() {
@@ -70,16 +71,24 @@ fn c2a2() {
#[allow(dead_code)]
fn c2a3() {
let vec = util::read_to_vector("data/c2a3.txt").unwrap();
let r = heap(&vec);
let v = util::read_to_vector("data/c2a3.txt").unwrap();
let r = heap(&v);
println!("c2a3={:?}", r);
}
#[allow(dead_code)]
fn c2a4() {
let v = util::read_to_vector("data/c2a4.txt").unwrap();
let r = find_two_sums(v);
println!("c2a4={:?}", r);
}
fn main() {
// c1a2();
// c1a3();
// c1a4();
// c2a1();
// c2a2();
c2a3();
// c2a3();
c2a4();
}

View File

@@ -1,37 +0,0 @@
def merge(a, b):
"""Merges two sorted lists"""
i, j = 0, 0
r = []
while i < len(a) and j < len(b):
if a[i] < b[j]:
r.append(a[i])
i += 1
else:
r.append(b[j])
j += 1
while i < len(a):
r.append(a[i])
i += 1
while j < len(b):
r.append(b[j])
j += 1
return r
def merge_sort(v):
length = len(v)
if length <= 1:
return v
half_length = length // 2
a = merge_sort(v[:half_length])
b = merge_sort(v[half_length:])
return merge(a, b)
if __name__ == "__main__":
print(merge_sort([42, 12, 3, 1, 5]))

13
src/two_sum.rs Normal file
View File

@@ -0,0 +1,13 @@
fn two_sum(t: i64, xs_vec: &Vec<i64>) {
}
pub fn find_two_sums(xs: Vec<i64>) -> usize {
0
}

View File

@@ -23,7 +23,7 @@ pub struct DirectedWeightedGraph {
pub distance: Vec<usize>,
}
pub fn read_to_vector(path: &str) -> Result<Vec<i32>, io::Error> {
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
let file = File::open(path)?;
let br = BufReader::new(file);
let mut v = Vec::new();