Data Structure and Algorithm 1CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT Danh sách liên kết Dr.. Data Structure and Algorithm 2Major Reference: • Robert Sedgewick, and Kevin Wayne, “Algorithms” Pri
Trang 1Data Structure and Algorithm 1
CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT
Danh sách liên kết
Dr Dao Nam Anh
Trang 2Data Structure and Algorithm 2
Major Reference:
• Robert Sedgewick, and Kevin Wayne, “Algorithms”
Princeton University, 2011, Addison Wesley
• Algorithm in C (Parts 1-5 Bundle)- Third Edition by
Robert Sedgewick, Addison-Wesley
• Cấu trúc dữ liệu và giải thuật, Đinh Mạnh Tường.
• Giải thuật và lập trình, Lê Minh Hoàng, Đại Học
Sư Phạm, 2002
Trang 3Data Structure and Algorithm 3
main() {
int i, N;
for (i = 1, N = 10; i <= 6; i++, N *= 10)
printf(“%7d %2d %9d\n, N, lg(i), N*lg(N)) }
Trang 4Data Structure and Algorithm 4
• Sử dụng cấu trúc dữ liệu để quản lý tập các dữ
liệu:
Các thao tác với dữ liệu nào là cần thiết
Triển khai các thao tác đó như thế nào
• Trong C ta dùng mảng, struct
• Ví dụ mảng trong C:
int A1[N]; int A2[N][M]; char str[50];
» A1[4]? A1[i] = *(A1+i)?
Trang 5Data Structure and Algorithm 5
• Mỗi node có 2 thành phần: phần dữ liệu và phần
liên kết chứa địa chỉ của node kế tiếp hay node
Trang 6Data Structure and Algorithm 6
Danh sách liên kết đơn
typedef struct node *link;
struct node {char ch; link next;}
Trang 7Data Structure and Algorithm 7
• Insert - Chèn
NULL
h
Trang 8Data Structure and Algorithm 8
• Insert - Chèn
NULL
f h
t x
(t after x)
Trang 9Data Structure and Algorithm 9
• Insert - Chèn
NULL
f h
t x
(t after x)
Trang 10Data Structure and Algorithm 10
• Insert - Chèn
NULL
f h
t x
(t after x)
Trang 11Data Structure and Algorithm 11
• Insert - Chèn
NULL
f h
Trang 12Data Structure and Algorithm 12
Trang 13Data Structure and Algorithm 13
Trang 14Data Structure and Algorithm 14
Trang 15Data Structure and Algorithm 15
Trang 16Data Structure and Algorithm 16
• Delete - Xóa
NULL
h
Trang 17Data Structure and Algorithm 17
Trang 18Data Structure and Algorithm 18
Trang 19Data Structure and Algorithm 19
Trang 20Data Structure and Algorithm 20
Trang 21Data Structure and Algorithm 21
Trang 22Data Structure and Algorithm 22
Trang 23Data Structure and Algorithm 23
Trang 24Data Structure and Algorithm 24
m g
c b
a h
NULL
Trang 25Data Structure and Algorithm 25
m g
c b
(delete after h) a
h
NULL
Trang 26Data Structure and Algorithm 26
f
t
(insert t after x)
m g
c b
e x
a h
NULL
Trang 27Data Structure and Algorithm 27
f
t
(insert t after x)
m g
c b
e x
a h
NULL
Trang 28Data Structure and Algorithm 28
f
t
(insert t after x)
m g
c b
e x
a h
NULL
Trang 29Data Structure and Algorithm 29
f
m g
c b
e a
h
NULL
Trang 30Data Structure and Algorithm 30
m g
c b
a h
m g
c b
a h
Trang 31Data Structure and Algorithm 31
m g
c b
a h
m g
c b
a h
Trang 32Data Structure and Algorithm 32
m g
c b
a h
m g
c b
a h
Trang 33Data Structure and Algorithm 33
•
https://sites.google.com/site/daonamanhedu/data-structure-algorithm