This commit is contained in:
ivans 2024-05-30 14:10:09 +04:00
parent 760763c667
commit 30ee797f0a
18 changed files with 37 additions and 7 deletions

Binary file not shown.

View File

@ -4,6 +4,6 @@
"\\KursiveWork", "\\KursiveWork",
"\\KursiveWork\\KursiveWork" "\\KursiveWork\\KursiveWork"
], ],
"SelectedNode": "\\KursiveWork\\KursiveWork\\infoform.cs", "SelectedNode": "\\KursiveWork\\KursiveWork\\MainForm.cs",
"PreviewInSolutionExplorer": false "PreviewInSolutionExplorer": false
} }

Binary file not shown.

Binary file not shown.

View File

@ -102,7 +102,7 @@ public class LinkedListStorage
} }
public List<LinkedListState> Load(string filename) public List<LinkedListState> Load(string filename)
{ {
states.Clear(); //states.Clear();
currentIndex = 0; currentIndex = 0;
using (BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open))) using (BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open)))

View File

@ -22,10 +22,18 @@ public class LinkedListVisualizer
{ {
// Заливка фона // Заливка фона
g.Clear(Color.White); g.Clear(Color.White);
//Отрисовка головы
g.DrawString("Head", new Font("Arial", 12), Brushes.Black, new Point(10, 15));
g.DrawLine(Pens.Black, 55, 25, 20 + NodeWidth + NodeSpacing, 25);
g.DrawPolygon(Pens.Black, new Point[] {
new Point(28 + NodeWidth + NodeSpacing, 25),
new Point(28 + NodeWidth + NodeSpacing - 5, 20),
new Point(28 + NodeWidth + NodeSpacing - 5, 30)
});
// Рисование узлов // Рисование узлов
Node current = state.Head; Node current = state.Head;
int x = NodeSpacing; int x = 70 + NodeSpacing;
while (current != null) while (current != null)
{ {
// Рисование узла // Рисование узла
@ -35,17 +43,36 @@ public class LinkedListVisualizer
// Рисование стрелки // Рисование стрелки
if (current.Next != null) if (current.Next != null)
{ {
g.DrawLine(Pens.Black, x + NodeWidth, 25, x + NodeWidth + NodeSpacing, 25); g.DrawLine(Pens.Black, x + NodeWidth, 25, x + NodeWidth + NodeSpacing - 7, 25);
g.DrawPolygon(Pens.Black, new Point[] { g.DrawPolygon(Pens.Black, new Point[] {
new Point(x + NodeWidth + NodeSpacing, 25), new Point(x + NodeWidth + NodeSpacing, 25),
new Point(x + NodeWidth + NodeSpacing + 5, 20), new Point(x + NodeWidth + NodeSpacing - 5, 20),
new Point(x + NodeWidth + NodeSpacing + 5, 30) new Point(x + NodeWidth + NodeSpacing - 5, 30)
});
}
else
{
g.DrawLine(Pens.Black, x + NodeWidth, 25, x + NodeWidth + NodeSpacing - 7, 25);
g.DrawPolygon(Pens.Black, new Point[] {
new Point(x + NodeWidth + NodeSpacing, 25),
new Point(x + NodeWidth + NodeSpacing - 5, 20),
new Point(x + NodeWidth + NodeSpacing - 5, 30)
}); });
} }
x += NodeWidth + NodeSpacing; x += NodeWidth + NodeSpacing;
current = current.Next; current = current.Next;
} }
if (current == null)
{
//g.DrawLine(Pens.Black, x + NodeWidth - 50, 25, x + NodeWidth + NodeSpacing - 50, 25);
//g.DrawPolygon(Pens.Black, new Point[] {
// new Point(x + NodeWidth + NodeSpacing - 50, 25),
// new Point(x + NodeWidth + NodeSpacing - 55, 20),
// new Point(x + NodeWidth + NodeSpacing - 55, 30)
// });
g.DrawString("NULL", new Font("Arial", 12), Brushes.Black, new Point(x + NodeWidth / 2 - 15, 15));
}
} }
return bitmap; return bitmap;
} }

View File

@ -32,6 +32,7 @@ namespace KursiveWork
manager = new LinkedListManager(parameters); manager = new LinkedListManager(parameters);
Controls.Add(pictureBox); Controls.Add(pictureBox);
pictureBox.Image = visualizer.Visualize(list.CreateState()); pictureBox.Image = visualizer.Visualize(list.CreateState());
manager.storage.AddState(list.CreateState());
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
@ -123,7 +124,9 @@ namespace KursiveWork
if (saveFileDialog.FileName != "") if (saveFileDialog.FileName != "")
{ {
manager.storage.Save(saveFileDialog.FileName); // Сохраняем в текстовый файл manager.storage.Save(saveFileDialog.FileName); // Сохраняем в текстовый файл
MessageBox.Show("Файл сохранен");
} }
else MessageBox.Show("Ошибка сохранения");
} }
private void LoadToolStripMenuItem_Click(object sender, EventArgs e) private void LoadToolStripMenuItem_Click(object sender, EventArgs e)