Professional Documents
Culture Documents
EX06 NguyenAnhTu N20DCDT026
EX06 NguyenAnhTu N20DCDT026
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using static QueueLinklist.Form1;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace QueueLinklist
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int DeQueue()
{
if (IsEmpty())
{
return -1;
}
int element = front.element;
front = front.next;
size--;
if (IsEmpty())
{
rear = null;
}
return element;
}
}
}
private QueueLinkedlist queue = new QueueLinkedlist();
lstHT.Items.Clear();
Node node = queue.front;
string itemstring = "";
while (node != null)
{
itemstring += node.element + " ";
lstHT.Items.Add($"Phần tử đã xóa {itemstring}");
node = node.next;
}
}
else
{
MessageBox.Show("Hàng đợi đã rỗng hoặc không thể xóa phần tử đầu tiên!");
}
}
Ví dụ:
- Thêm phần tử 5 6 7 8 vào hàng đợi :
- Xóa phần tử theo tính chất FIFO:
- Hiển thị số lượng phần tử có trong hàng đợi:
LEFT ROOT RIGHT
Code:
using System;
namespace dsc
{
class Program
{
class Node
{
public int element;
public Node left;
public Node right;
public Node(int e, Node l, Node r)
{
element = e;
left = l;
right = r;
}
}
class BinarySearchTree
{
private Node root;
public BinarySearchTree()
{
root = null;
}