reorg and finished howework2 algorithms