// Thêm phâ`n tu? va`o cuô´i public void InsertLast(SV data) { Node node = new Node(data); if (head == null) { head = tail = node; } else { tail.nextLink = node; tail = node; } }
// Thêm phâ`n tu? va`o dâ`u public void InsertFirst(SV data) { Node node = new Node(data); if (head == null) { head = tail = node; } else { node.nextLink = head; head = node; } }
// Sort public void InterchangeSort() { for (Node p = head; p != tail; p = p.nextLink) { for (Node q = p.nextLink; q != null; q = q.nextLink) { if (int.Parse(p.data.maSV) > int.Parse(q.data.maSV)) { SV t = p.data; p.data = q.data; q.data = t; } } } }
static void Main(string[] args) { taoListSV(); Console.WriteLine("Nhap vao so luong sinh vien muon in ra man hinh:"); int n = int.Parse(Console.ReadLine()); listSV.PrintList(n); //Bang lua chon Console.WriteLine("Chon 1 de xoa/Chon 2 de them"); Console.WriteLine("Chon: "); int chon = int.Parse(Console.ReadLine()); if (chon == 1) { //Xoa sinh vien theo MaSV Console.WriteLine("Nhap STT can xoa: "); string canXoa = Console.ReadLine(); listSV.RemoveNode(canXoa); n = n - 1; listSV.PrintList(n); } if (chon == 2) { //Them sinh vien Console.WriteLine("Nhap so Sv can them: "); string canThem = Console.ReadLine(); SV svThem = new SV("10", "Ouip", 9.0, 9.0, 9.0, 9.0, 9.0); listSV.InsertLast(svThem); n = n + 1; listSV.PrintList(n); } //Sort listSV.InterchangeSort(); PrinListSV(); Console.ReadKey(); }
// Constructor public Node(SV data) { this.data = data; }