งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

Linked List ( ต่อ ) Lecturer : Kritawan Siriboon, Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++,… Mark Allen Weiss, Addison Wesley.

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "Linked List ( ต่อ ) Lecturer : Kritawan Siriboon, Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++,… Mark Allen Weiss, Addison Wesley."— ใบสำเนางานนำเสนอ:

1 Linked List ( ต่อ ) Lecturer : Kritawan Siriboon, Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++,… Mark Allen Weiss, Addison Wesley

2 this pointer template class point{ int x, y; public: void move(int xx, int yy) { } }; x += xx; y += yy; this->x += xx; this->y += yy; point p, q; p.move(1,2); // this keeps &p q.move(3,4); // this keeps &q same as When an object calls a member function, the object’s address is passed automatically to the function as ‘this’ pointer. เมื่อออปเจคใดๆ เรียกเมมเบอร์ฟังก์ชั่น แอดเดรสของออปเจคนั้นจะถูกส่งมายังฟังก์ชั่น นั้นโดยอัตโนมัติในรูป this พอยน์เตอร์ (*this).x += xx; (*this). y += yy;

3 Dummy Node Can insert / delete to any position? p Using “Dummy Node” dummy head dummy head Empty List

4 Head & Tail Nodes Curcular List head tail

5 Doubly VS Singly Linked List Doubly Curcular List tailhead prev data next tail previous prev data next

6 Linked Stack Linked Queue top front rear Check if it support every operations.

7 Lab : Scrambling List h Cut it. Take the bottom up. I love you very much C++ Where ? h2 t2 t1 Now try. Print h2. Opps!

8 Lab : Scrambling List h1 Shuffle. 4 5 6 7 8 9 t1 1 2 3 h2 t2

9 Lab : Scrambling List h1 Shuffle. 4 5 6 7 8 9 t1 1 2 3 h2 t2

10 Linked Array Implementation List : ABCDEFG Create Available List (Stack) node n[8]; int avail = 0; avail = 1 2 3 4 5 6 7 2 3 5 4 6 7 1 avail =

11 2 3 5 4 6 7 1 Using avialable node from avail stack. av= Returning avialable node to avail stack. 2 3 5 4 6 7 1 av= take out 1st node take out another node 2 3 5 4 6 7 1 av= take out another node 2 3 5 4 6 7 1 av= return node 2 first 2 3 6 4 6 7 1 av=

12 old_av= avail; avail = n[avail].next ; n[old_av].data = d; n[old_av].next = nx; return old_av; getnode() node n[8]; int avail = 0; avail = 2 3 5 4 6 7 1 int h = getnode(d,nx) h = A -1A 0 old_av = results 3 5 4 6 7 1 av= A -1 h =

13 p h insertafter() X q E D C B A 5 h = 0 3 7 av = 6 1 p = insertafter(p,d); int q = getnode(d,n[p].next); n[p].next = q; node n[8]; q = X 04 0 results h= av= p= q= 3 -1 5 7 0 4 1 C A D X B E

14 deleteafter() int i = delteafter(p); p h E D C B A 5 h = 0 3 7 av = 6 1 p = q q = 3 C 3 int q = n[p].next; n[p].next = n[q].next; results h= av= p= q= 3 -1 5 7 6 3 1 C A D B E

15 0 1 2 3 12 13 14 4 5 6 7 8 9 10 11 Sharing pool of nodes. B Z Y X 5 h = 0 9 1 av = 6 r = top = queue : r h g f C W 2 12 C f = r 7 h 3 g 14 f 13 11 top C B stack : A r f Circular List: W X Y Z h

16 Sequential Array Insertion / Deletion Shifting Problem. Random Access. Static Allocation. Only keeps data. Solved. Sequential Access. Dynamic Allocation. Need space for linkes. Dynamic h

17 Application : Polynomial expression 5x 3 + 4x 2 - 7x + 10 x 3 + 2x - 8 + How about... 5x 85 + 7x + 1 x 76 - 8 +

18 Application : Multilists 1. class หนึ่งๆ มีใครลงบ้าง 2. นร. คน หนึ่งๆ ลง class ใดบ้าง C1 C2 C3 C4 s1s2 s3s4s5

19 Application : Multilists 1. class หนึ่งๆ มีใครลงบ้าง 2. นร. คน หนึ่งๆ ลง class ใดบ้าง C1 C2 C3 C4 s1 s2 s3 s4 s5 01230123 0 1 2 3 4 s1 c1 s3 c1 s3 c2s5 c2 s3 c3 s4 c3 s1 c3 s2 c4s4 c4

20 Application : Radix Sort 01234567890123456789 01234567890123456789 01234567890123456789 input: 64 8 216 512 27 729 0 1 343 125 6464 6464 6464 8 8 8 216216 216216 216216 512512 512512 512512 2727 2727 2727 72 9 0 0 0 1 1 1 34 3 125125 125125 125125 output : 0 1 8 27 64 125 216 343 512 729

21 Application : Radix Sort 01234567890123456789 input: 64 8 216 512 27 729 0 1 343 125 output: 0 1 8 27 64 125 216 343 512 729 01234567890123456789 648 216 512 27 72 9 0 1 343 125 64 8 216 512 27 7290 1 343125 01234567890123456789 64 8 216 512 27 729 0 1 343 125


ดาวน์โหลด ppt Linked List ( ต่อ ) Lecturer : Kritawan Siriboon, Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++,… Mark Allen Weiss, Addison Wesley.

งานนำเสนอที่คล้ายกัน


Ads by Google