| Last change
 on this file since ebadb5d was             5717495, checked in by Michael Brooks <mlbrooks@…>, 3 years ago | 
        
          | 
Start of the linked-list chapter.
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            423 bytes | 
      
      
| Rev | Line |  | 
|---|
| [5717495] | 1 | #include <sys/queue.h> | 
|---|
|  | 2 | #include <stdio.h> | 
|---|
|  | 3 |  | 
|---|
|  | 4 |  | 
|---|
|  | 5 |  | 
|---|
|  | 6 | int main() { | 
|---|
|  | 7 |  | 
|---|
|  | 8 |  | 
|---|
|  | 9 |  | 
|---|
|  | 10 |  | 
|---|
|  | 11 |  | 
|---|
|  | 12 |  | 
|---|
|  | 13 |  | 
|---|
|  | 14 |  | 
|---|
|  | 15 |  | 
|---|
|  | 16 |  | 
|---|
|  | 17 |  | 
|---|
|  | 18 |  | 
|---|
|  | 19 |  | 
|---|
|  | 20 | // C | 
|---|
|  | 21 |  | 
|---|
|  | 22 | struct req { | 
|---|
|  | 23 | int pri, rqr; | 
|---|
|  | 24 | LIST_ENTRY(req) x; | 
|---|
|  | 25 | }; | 
|---|
|  | 26 |  | 
|---|
|  | 27 | LIST_HEAD(reql, req); | 
|---|
|  | 28 |  | 
|---|
|  | 29 | struct reql reqs; | 
|---|
|  | 30 | LIST_INIT(&reqs); | 
|---|
|  | 31 |  | 
|---|
|  | 32 | struct req | 
|---|
|  | 33 | r1 = {1, 42}, | 
|---|
|  | 34 | r2 = {2, 42}; | 
|---|
|  | 35 |  | 
|---|
|  | 36 | LIST_INSERT_HEAD( | 
|---|
|  | 37 | &reqs, &r2, x); | 
|---|
|  | 38 | LIST_INSERT_HEAD( | 
|---|
|  | 39 | &reqs, &r1, x); | 
|---|
|  | 40 |  | 
|---|
|  | 41 |  | 
|---|
|  | 42 |  | 
|---|
|  | 43 |  | 
|---|
|  | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
|  | 48 |  | 
|---|
|  | 49 |  | 
|---|
|  | 50 |  | 
|---|
|  | 51 | struct req *cur; | 
|---|
|  | 52 | LIST_FOREACH(cur, &reqs, x) | 
|---|
|  | 53 | printf("{%d %d} ", cur->pri, cur->rqr); | 
|---|
|  | 54 | printf("\n"); | 
|---|
|  | 55 |  | 
|---|
|  | 56 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.