using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; using System.IO; namespace ProjectKnapsack.classes; public class Storage { private List states; private int currentPosition; public Storage() { states = new List(); currentPosition = 0; } public void AddState(KnapsackState state) { states.Add(state); } public KnapsackState GetState(int index) { return states[index]; } public int StateCount => states.Count; public void SaveToFile(string filename) { var options = new JsonSerializerOptions { WriteIndented = true }; var json = JsonSerializer.Serialize(states, options); File.WriteAllText(filename, json); } public void LoadFromFile(string filename) { var json = File.ReadAllText(filename); states = JsonSerializer.Deserialize>(json); } }