trekhleb / javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
185.25k stars 29.89k forks source link

Fix BUG in graph reverse method & Add needed tests #916

Open itsamirhn opened 1 year ago

itsamirhn commented 1 year ago

This PR fix the issue in #873.

The issue was in the old reverse method, edges reversed one by one and this was making issue for graphs with cycle of length 2. For example, when graph with only two edges AB and BA was reversing, on reversing AB, BA was exist and there will be crash.

itsamirhn commented 1 year ago

Would you please check this PR? @trekhleb