Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: C++  |  size: 0.83 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // wsk->zm to (*wsk).zm czyli wyłuskanie adresu obiektu struktury
  5.  
  6. typedef struct list_element
  7. {
  8.         struct list_element *next;
  9.         int value;
  10. } element;
  11.  
  12. int insert_end(element *&lista, int wartosc)
  13. {
  14.         element *nowy;
  15.         element *help;
  16.         help=lista;
  17.         nowy = (element*)malloc(sizeof(element));
  18.         nowy->value = wartosc;
  19.         nowy->next = NULL;
  20.         if(lista==NULL)
  21.         {
  22.                 lista = nowy;
  23.                 return 0;
  24.         }
  25.         while(help->next != NULL)
  26.         {
  27.                 help = help->next;
  28.         }
  29.         help->next = nowy;
  30.  
  31.         return 0;
  32. }
  33.  
  34. int read(element *lista)
  35. {
  36.         element *help = lista;
  37.         while(help->next!=NULL)
  38.         {
  39.                 printf("%d\n",help->value);
  40.                 help = help->next;
  41.         }
  42.         printf("%d\n",help->value);
  43.         return 0;
  44. }
  45.  
  46. int main()
  47. {
  48.         element *list = NULL;
  49.         insert_end(list,10);
  50.         insert_end(list,15);
  51.         insert_end(list,20);
  52.         read(list);
  53. }