lý thuyết danh sách liên kết

3 387 2
lý thuyết danh sách liên kết

Đang tải... (xem toàn văn)

Thông tin tài liệu

Lý thuyết về danh sách liên kết trong C++ Upload cho các bạn năm một học trường công nghệ thông tin, các bạn có thể tham khảo, có gì thắc mắc xin liên hệ.....................................................................................................................................................................................

C Code: Select All | Show/Hide 1. struct tq { 2. thtin_t phantu; 3. struc tq*tiep; 4. }; 5. typedef struct tq tq_t; 2.Con trỏ tới 1 node C Code: Select All | Show/Hide 1. struct node { 2. int infor; 3. struct node *next; 4. }; 5. typedef struct node *NODEPTR; 3.Cấp phát bộ nhớ cho 1 node C Code: Select All | Show/Hide 1. NODEPTR Getnode(void) { 2. NODEPTR p; 3. P = (NODEPTR) malloc (sizeof( struct node)); 4. Return(p); 5. } 4.Giải phóng 1 node C Code: Select All | Show/Hide 1. NODEPTR Freenode( NODEPTR p){ 2. free (p); 3. } 5.Thêm phần tử vào đỉnh danh sách C Code: Select All | Show/Hide 1. void Push_Top( NODEPTR *plist, int x) { 2. NODEPTR p; 3. p= Getnode(); 4. p -> infor = x; 5. p ->next = *plist; 6. *plist = p; 7. } 6.Thêm node mới vào cuối danh sách C Code: Select All | Show/Hide 1. void Push_Bottom( NODEPTR *plist, int x) { 2. NODEPTR p, q; 3. p= Getnode(); // 4. p->infor = x; 5. q = *plist; 6. while (q-> next != NULL) 7. q = q -> next; 8. 9. q -> next = p; 10. p ->next = NULL; 11. } 7.Thêm node mới vào giữa danh sách C Code: Select All | Show/Hide 1. void Push_Before( NODEPTR p, int x ){ 2. NODEPTR q; 3. if (p->next==NULL) 4. Push_Bottom(p, x); 5. else { 6. q= Getnode(); 7. q -> infor = x; 8. q-> next = p-> next; 9. p->next = q; 10. } 11. } 8.Xóa 1 node đầu danh sách C Code: Select All | Show/Hide 1. void Del_Top( NODEPTR *plist) { 2. NODEPTR p; 3. p = *plist; 4. if (p==NULL) return; 5. (*plist) = (*plist) -> next; 6. p-> next = NULL; 7. Freenode(p); 8. } 9.Xóa node cuối danh sách C Code: Select All | Show/Hide 1. void Del_Bottom(NODEPTR *plist) { 2. NODEPTR p, q; 3. if (*plist==NULL) return; 4. else if ( (*plist)->next==NULL)) 5. Del_Top(plist); 6. else { 7. p = *plist; 8. while (p->next!=NULL){ 9. q = p; 10. p = p->next; 11. } 12. // p lµ node cuèi danh s¸ch; 13. q->next =NULL; 14. Freenode(p); 15. } 16. } 10.Xóa node giữa danh sách C Code: Select All | Show/Hide 1. void Del_before(NODEPTR p){ 2. NODEPTR q; 3. if (p->next==NULL) return; 4. q = p ->next; 5. p->next = q->next; 6. Freenode(q); 7. } . p; 10. p = p->next; 11. } 12. // p lµ node cuèi danh s¸ch; 13. q->next =NULL; 14. Freenode(p); 15. } 16. } 10.Xóa node giữa danh sách C Code: Select All | Show/Hide 1. void Del_before(NODEPTR. Getnode(); 4. p -> infor = x; 5. p ->next = *plist; 6. *plist = p; 7. } 6.Thêm node mới vào cuối danh sách C Code: Select All | Show/Hide 1. void Push_Bottom( NODEPTR *plist, int x) { 2. NODEPTR. -> next; 8. 9. q -> next = p; 10. p ->next = NULL; 11. } 7.Thêm node mới vào giữa danh sách C Code: Select All | Show/Hide 1. void Push_Before( NODEPTR p, int x ){ 2. NODEPTR q; 3.

Ngày đăng: 08/09/2014, 08:41

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan