Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. typedef struct lista{
  6.     int wartosc;
  7.     struct lista *pref;
  8.     struct lista *next;
  9.  
  10. } lista;
  11.  
  12. lista * head;
  13.  
  14. void addElement (lista * pierwszyelement, int wartoscc){
  15.     lista *current, *newElement;
  16.     current = pierwszyelement;
  17.         while(current-> next != NULL){
  18.             current=current-> next;
  19.         };
  20.     newElement = malloc(sizeof(struct lista));
  21.     newElement-> wartosc = wartoscc;
  22.     newElement-> pref = current;
  23.     newElement->next = current-> next;
  24.     current-> next = newElement;
  25.  
  26. }
  27.  
  28. void view (lista * pierwszyelement){
  29.     lista *current, *newElement;
  30.     current = pierwszyelement;
  31.         while(current-> next != NULL){
  32.             printf("\n wartosc %d",  current -> wartosc);
  33.             printf("\n next %d",  current -> next);
  34.             printf("\n pref %d \n \n",  current -> pref);
  35.             current=current-> next;
  36.  
  37.         };
  38.  
  39. }
  40.  
  41.  
  42. int main()
  43. {
  44.     head = malloc(sizeof(struct lista));
  45.     head -> wartosc = 12 ;
  46.     head -> pref = NULL;
  47.     head -> next = NULL;
  48.  
  49.     addElement (head, 6);
  50.     addElement (head, 5);
  51.     addElement (head, 4);
  52.     addElement (head, 3);
  53.     addElement (head, 2);
  54.     addElement (head, 1);
  55.  
  56.     view(head);
  57.  
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement