Danh sách kết nối kép - Pdf 30

// Dia chi email cua 2 lop '';
''
// Day la bai tap ban Quy lop Tk62 hoi toi, toi da sua theo y cua
ban //ay, cac em xem tham khao nhe.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace danh_saach_noi_kep
{
class dnode
{
public string tenchinhanh;
public string diachi;
public int sodienthoai;
public dnode pre;
public dnode next;
}
class list
{
public dnode head, tail;
}
class Program
{
static dnode Ggetnode(string x, string y, int z)
{
dnode p = new dnode();
if (p == null)
{
throw new Exception("khong du bo nho");
}

l.tail.next = p;
p.pre = l.tail;
l.tail = p;
}
}
}
static dnode Tim(list l, string x, string y, int z)
{
dnode p = new dnode();
while ((p != null) && (p.tenchinhanh != x) && (p.diachi !=
y) && (p.sodienthoai != z))
{
//p = l.head; ko tim duoc cau lenh nay, va luon la vong
lap vo han neu danh sach khac rong hoac nut can tim ko phai la nut dau
tien, vi em luon gan con tro p ve dau danh sach
p = p.next;
} return p;
}
static void themdau(ref list l, dnode p)
{
if (l.head == null)
{
l.head = l.tail = p;
}
else
{
p.next = l.head;
l.head.pre = p;
l.head = p;
}

}
else
{ chendau(ref l, x, y, z); }
}
// Tuong tu nhu thu tuc o tren
static void chentruocmotphantu(ref list l, dnode q, string x,
string y, int z)
{
/*Console.WriteLine("ban muon them vao phan tu truoc phan
tu nay .");
Console.Write("Ten chi nhanh :"); string a =
Console.ReadLine();
Console.Write("Ten chi nhanh :"); string b =
Console.ReadLine();
Console.Write("so dien thoai :"); int c =
int.Parse(Console.ReadLine());
q = Tim(l, a, b, c);*/
// doan nay cung bi sai
dnode s = q.pre;
dnode p = Ggetnode(x, y, z);
if (q != null)
{
p.next = q; p.pre = s; q.pre = p;
if (s != null)
{
s.next = p;
}
if (q == l.head)
{ l.head = p; }
}

p = p.next;
}
}
//static void Hien1(list l)
//{
// dnode p = new dnode();
// p = l.head;
// while (p != null)
// {
// Console.WriteLine("\t{0}\t{1}\t{2}\n", p.tenchinhanh,
p.diachi, p.sodienthoai);
// p = p.pre;
// }
//}
static void Xoadau(ref list l)
{
dnode p; //=new dnode();
if (l.head != null)
{
p = l.head;
l.head = l.head.next; // dich chuyen con tro head den
nut tiep theo
// l.head.pre = null; // neu danh sach rong se sinh ra
loi o cau lenh nay
p = null; // huy bo nut dau tien trong danh sach
if (l.head == null) // danh sach rong
l.tail = null;
else
l.head.pre = null; // gan truong pre cua nut dau
tien trong danh sach moi bang null

//Console.Write("so dien thoai :"); int c =
int.Parse(Console.ReadLine());
//q = Tim( l, a, b, c);
if (q != null)
{
dnode p = q.next;
if (p != null)
{
q.next = p.next;
if (p == l.tail)
l.tail = q;
else
p.next.pre = q; // nut tiep theo cua nut bi xoa
co truong pre tro den q
p = null;
}
else
{ Xoadau(ref l); }
}
}
static void xoatruocphantuq(ref list l, dnode q)
{
// Console.WriteLine("ban muon xoa truoc phan tu nao");
// Console.Write("Ten chi nhanh :"); string a =
Console.ReadLine();
// Console.Write("Ten chi nhanh :"); string b =
Console.ReadLine();
// Console.Write("so dien thoai :"); int c =
int.Parse(Console.ReadLine());
// dnode p = new dnode();


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status