Project Tasks:
1. Create a class for the heap data structure, where a heap (min-order) is implemented using an array.
2. Create another class for testing your data structure, where in the Main method, do the following:
3. Create a method to display the heap by drawing it as a binary tree on screen. Use Graphics to draw the heap.
For Example, if the binary tree array is 11, 6, 4, 5, 8, 10, 19, 17, 43, 31, 49. You are supposed to draw a tree shown as follows: see image.
You can design the shape of your tree. For example, you can decide where to positon nodes and lines. The following example shows you how to use graphics to define the size and color of the circle and draw a circle on a form.
//Define pen, brush and graphics
Pen bluePen = new Pen(Color.Blue, 3);
SolidBrush drawBrush = new SolidBrush(Color.Azure);
Graphics graphics = this.CreateGraphics();
graphics.DrawEllipse(bluePen, 100, 200, 50, 50);
graphics.FillEllipse(drawBrush, 100, 200, 50, 50);
The following example shows you how to use graphics to draw a line:
graphics.DrawLine(bluePen, 225, 325, 375, 325);
The following example shows you how to use graphics to display a string:
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
RectangleF drawRect = new RectangleF(x, y, width, width);
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
// Draw string to screen.
graphics.DrawString(“test”, drawFont, drawBrush, drawRect, drawFormat);
* More details about Graphics class can be found though the following URL:
https://msdn.microsoft.com/en-us/library/System.Drawing.Graphics(v=vs.110).aspx