Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct car{
  5. double data;
  6. int id;
  7. struct car *next;
  8. };
  9. struct fifo_pointers{
  10. struct car *first, *last;
  11. }kol;
  12. void push(struct fifo_pointers *kol, double data, int id){
  13. struct car *new_node=(struct car*)malloc(sizeof(struct car));
  14. if(new_node){
  15. new_node->data=data;
  16. new_node->id=id;
  17. new_node->next=NULL;
  18. if(kol->first==NULL)
  19. kol->first=kol->last=new_node;
  20. else{
  21. kol->last->next=new_node;
  22. }
  23. }
  24. else puts("Nowy element nie zostal utworzony!");
  25. }
  26. void pop_at_front(struct fifo_pointers *kol){
  27. if(kol->first){
  28. struct car *tmp=kol->first->next;
  29. free(kol->first);
  30. kol->first=tmp;
  31. if(tmp==NULL)
  32. kol->last=NULL;
  33. }
  34. else puts("Kolejka nie istnieje");
  35. }
  36. void wyswietl(struct fifo_pointers kol){
  37. while(kol.first){
  38. printf("ID: %d\n", kol.first->id);
  39. printf("Data: %.1f\n", kol.first->data);
  40. kol.first=kol.first->next;
  41.  
  42. }
  43. puts(" ");
  44. }
  45. int main()
  46. {
  47. push(&kol, 10.2, 23);
  48. wyswietl(kol);
  49. pop_at_front(&kol);
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement