1 / 12

CSI 400/500 Operating Systems Spring 2009

CSI 400/500 Operating Systems Spring 2009. LAB - Dynamic Allocation in C Using Linked Lists Week of February 24-26. Creating structures in C. Use struct keyword Create new variable class using typedef Can nest structures Simple way to gather data that defines a particular data item.

dane-dodson
Download Presentation

CSI 400/500 Operating Systems Spring 2009

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. CSI 400/500 Operating SystemsSpring 2009 LAB - Dynamic Allocation in C Using Linked Lists Week of February 24-26

  2. Creating structures in C • Use struct keyword • Create new variable class using typedef • Can nest structures • Simple way to gather data that defines a particular data item

  3. Dynamic structures • Can combine malloc and sizeof to allocate dynamic storage of structures • Conducive to creating lists of structure elements

  4. Dynamic Linked List • Linear chain of structures created during execution • Definitions: • NODE : individual item on chain • FIELD : individual data item in node • HEAD : start of chain • TAIL : end of chain • NEXT : pointer to next node • NULL : no node at end of pointer

  5. Linked List implementation in C • Most linked lists require two structures: • One for data contained in node • One for node • Nodes created by obtaining storage, setting data value, and initializing *next and *prev to 0

  6. Linked List functions • So now we have one -- what do we do with it? • Insert new node • Remove existing node • Find a given node • List all nodes

  7. Inserting a node • Receive key value of new node • Obtain storage • Check if list exists • Find location in list • Do not add if already exists • Add to list

  8. Record look-ahead

  9. Deleting a node • Find it • Reset pointers to remove it from list • Free storage

  10. Finding a node

  11. List values in list • Appears in sorted order automatically

  12. Why discuss lists in an Operating Systems course? • Many operating systems use lists as their queues • Others use more complex structures like trees and hash tables, which will be discussed later in this course

More Related