Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct lista{
  4. int a;
  5. struct lista *next;
  6. };
  7.  
  8. struct lista *head;
  9.  
  10. void add(int x)
  11. {
  12.     struct lista *temp = (struct lista*)malloc(sizeof(struct lista));
  13.     temp->a = x;
  14.     temp->next = NULL;
  15.     if(head!=NULL){
  16.         temp->next = head;
  17.         }
  18.  
  19.     head=temp;
  20.  
  21. }
  22.  
  23. void print()
  24. {
  25.     struct lista *temp = head;
  26.     printf("List is: ");
  27.     while(temp!=NULL)
  28.     {
  29.         printf(" %d",temp->a);
  30.         temp = temp->next;
  31.     }
  32.     printf("\n");
  33.  
  34. }
  35.  
  36. int main ()
  37. {
  38.     int x,i,a;
  39.     printf("Ile chcesz elementow w liscie?\n");
  40.     scanf("%d",&x);
  41.     for(i=1; i<=x; i++)
  42.         scanf("%d",&a);
  43.         add(a);
  44.  
  45.     print();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement