Attachment 'list.c'

Download

   1 #include <stdio.h> 
   2 
   3 typedef int *int_ptr; /* новое имя типа */
   4 int_ptr pi; /* сокращение для int *pi */
   5 
   6 struct node1 { /* node1 -- тег структуры. используем какое-нибудь ненужное имя*/
   7     int val;
   8     struct node1 *next;
   9 };
  10 
  11 typedef struct node1 node;
  12 typedef node* list; 
  13 
  14 int main (int argc, char **argv)
  15 {
  16   list i;
  17   
  18   node n1, n2;
  19   
  20   n1.val = 1;
  21   n2.val = 2;
  22   
  23   n1.next = &n2; /* ссылка на следующий элемент */
  24   n2.next = NULL; /* дальше тупик */
  25   
  26   printf( "n1: val = %d, next = %u\n", n1.val, n1.next );
  27   printf( "n2: val = %d, next = %u\n", n2.val, n2.next );
  28 
  29   
  30 
  31   i = &n1; 
  32   while(i != NULL) {
  33     printf("%d\n", (*i).val );
  34     i = (*i).next; 
  35   }
  36   
  37   return 0;
  38 }
  39  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.