Advertisement
Patresss

Untitled

Aug 31st, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct tnode{
  5. int val;
  6. struct tnode *next;
  7. };
  8. typedef struct tnode node;
  9.  
  10. void dodaj_na_koniec (node **head)
  11. {
  12.  
  13. node *new=malloc(sizeof(node));
  14. if (new==NULL)
  15.     puts("Blad w alokacji");
  16.  
  17. new->next=NULL;
  18.  
  19. if(*head==NULL)
  20. {
  21.  
  22.     *head=new;
  23.     new->val=0;
  24.     printf("Tworzy nowa liste od wartosci: %d\n", new->val);
  25.  
  26. }
  27. else
  28.     {
  29.     node *temp=*head;
  30.     while(temp->next!=NULL)
  31.     {
  32.         temp=temp->next;
  33.     }
  34.     temp->next=new;
  35.     new->val=temp->val+1;
  36.     printf("Dodaje na koniec wartosc: %d\n",new->val);
  37. }
  38. }
  39.  
  40.  
  41. int main(void)
  42. {
  43.     node *head=NULL;
  44.  
  45.     dodaj_na_koniec (&head);
  46.     dodaj_na_koniec (&head);
  47.     dodaj_na_koniec (&head);
  48.     dodaj_na_koniec (&head);
  49.         dodaj_na_koniec (&head);
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement