Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct lista{
- int wartosc;
- struct lista *pref;
- struct lista *next;
- } lista;
- lista * head;
- void addElement (lista * pierwszyelement, int wartoscc){
- lista *current, *newElement;
- current = pierwszyelement;
- while(current-> next != NULL){
- current=current-> next;
- };
- newElement = malloc(sizeof(struct lista));
- newElement-> wartosc = wartoscc;
- newElement-> pref = current;
- newElement->next = current-> next;
- current-> next = newElement;
- }
- void view (lista * pierwszyelement){
- lista *current, *newElement;
- current = pierwszyelement;
- while(current-> next != NULL){
- printf("\n wartosc %d", current -> wartosc);
- printf("\n next %d", current -> next);
- printf("\n pref %d \n \n", current -> pref);
- current=current-> next;
- };
- }
- int main()
- {
- head = malloc(sizeof(struct lista));
- head -> wartosc = 12 ;
- head -> pref = NULL;
- head -> next = NULL;
- addElement (head, 6);
- addElement (head, 5);
- addElement (head, 4);
- addElement (head, 3);
- addElement (head, 2);
- addElement (head, 1);
- view(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement