1 / 13

Common Complex C Structures

Common Complex C Structures. C-minar 6 July 2004. To cover today:. Linked list Doubly linked list Binary Tree N-ary Tree. Linked List. What if you need to store ordered information where finding the ‘next’ element is necessary where insertion should be painless

Download Presentation

Common Complex C Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Common ComplexC Structures C-minar 6 July 2004

  2. To cover today: • Linked list • Doubly linked list • Binary Tree • N-ary Tree

  3. Linked List • What if you need to store • ordered information • where finding the ‘next’ element is necessary • where insertion should be painless • Then, the linked list is for you

  4. Linked List HEAD* • How to do Linked Lists: • Always keep a pointer to the head • Always point ‘tail’ element’s NEXT to NULL ListElem ListElem ListElem . . . NEXT* NEXT* NEXT* NULL

  5. n:ListElem n:NEXT* hNEXT* Linked List: Adding • Adding to a linked list: • Create new n:ListElem • n:ListElem.NEXT = h:NEXT • h:NEXT =n:ListElem b:ListElem b:NEXT*

  6. h:NEXT* n:ListElem n:NEXT* Linked List: Subtracting • Subtracting • h:NEXT = n:ListElem.NEXT • free n:ListElem b:ListElem b:NEXT*

  7. Linked List • What to watch out for: • Dangling pointers (from adding/subtracting in the wrong order) • Not pointing to NULL at the end • Accidentally losing your HEAD*

  8. Doubly-Linked List • What if you need to store • A list that is traversable in more than one way (i.e., backward and forward) • To be able to arbitrarily reorder the list • To be able to have a linked list, yet see behind you. 

  9. Doubly-Linked List HEAD* ListElem ListElem ListElem . . . PREV* NEXT* PREV* NEXT* PREV* NEXT* NULL

  10. Binary Tree • What if you need to • rapidly get to values in a table • sort these values to be easily accessed • drastically reduce time required to access data • be able to leap tall buildings in a single bound • Binary tree is what you nee(d)!

  11. node node node LEFT* LEFT* LEFT* RIGHT* RIGHT* RIGHT* Binary Tree ROOT*

  12. node node node node _a* _a* _a* _a* _b* _b* _b* _b* _c* _c* _c* _c* ... ... ... ... _n* _n* _n* _n* N-ary Tree ROOT*

  13. Homework • See website

More Related