Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct car{
- double data;
- int id;
- struct car *next;
- };
- struct fifo_pointers{
- struct car *first, *last;
- }kol;
- void push(struct fifo_pointers *kol, double data, int id){
- struct car *new_node=(struct car*)malloc(sizeof(struct car));
- if(new_node){
- new_node->data=data;
- new_node->id=id;
- new_node->next=NULL;
- if(kol->first==NULL)
- kol->first=kol->last=new_node;
- else{
- kol->last->next=new_node;
- }
- }
- else puts("Nowy element nie zostal utworzony!");
- }
- void pop_at_front(struct fifo_pointers *kol){
- if(kol->first){
- struct car *tmp=kol->first->next;
- free(kol->first);
- kol->first=tmp;
- if(tmp==NULL)
- kol->last=NULL;
- }
- else puts("Kolejka nie istnieje");
- }
- void wyswietl(struct fifo_pointers kol){
- while(kol.first){
- printf("ID: %d\n", kol.first->id);
- printf("Data: %.1f\n", kol.first->data);
- kol.first=kol.first->next;
- }
- puts(" ");
- }
- int main()
- {
- push(&kol, 10.2, 23);
- wyswietl(kol);
- pop_at_front(&kol);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement