#include #include struct fifo_node { char name[20]; char surname[20]; int class; char station_A[20]; char station_B[20]; int price; int data; struct fifo_node *next; }; struct fifo_pointers { struct fifo_node *head, *tail; } fifo; void enqueue(struct fifo_pointers *fifo) { struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node)); if(new_node) { new_node->next = NULL; if(fifo->head==NULL) fifo->head = fifo->tail = new_node; else { fifo->tail->next=new_node; fifo->tail=new_node;} puts("PODAJ IMIE:\n"); scanf("%s",new_node->name); puts("PODAJ NAZWISKO:\n"); scanf("%s",new_node->surname); do { printf("Podaj klase (1 lub 2):\n"); scanf("%d",&new_node->class); }while(new_node->class<0 || new_node->class>2); puts("PODAJ PUNKT POCZATKOWY:\n"); scanf("%s",new_node->station_A); puts("PODAJ PUNKT DOCELOWY:\n"); scanf("%s",new_node->station_B); } } void print_queue(struct fifo_pointers fifo) { while(fifo.head) { printf("%d ",fifo.head->data); fifo.head = fifo.head->next; } puts(""); } void print_queue_with_for(struct fifo_pointers fifo) { for(;fifo.head;fifo.head=fifo.head->next) printf("%d ",fifo.head->data); puts(""); } int main(void) { srand(time(NULL)); int i,a; while(1) { printf("\n\n1. DODAJ OSOBE:\n"); printf("2. WYSWIETL I USUN CALA KOLEJKE:\n"); printf("3. WYJSCIE\n"); scanf("%d",&a); if(a==1) { enqueue(&fifo); } if(a==2) { while(fifo.head!=NULL) { printf("\n*****************"); printf("\nImie pasazera:%s\n",fifo.head->name); printf("Nazwisko pasazera:%s\n",fifo.head->surname); printf("Klasa pociagu:%d\n",fifo.head->class); printf("Punkt poczatkowy:%s\n",fifo.head->station_A); printf("Punkt docelowy:%s\n",fifo.head->station_B); printf("Cena biletu:%lf\n",fifo.head->price); fifo.head=fifo.head->next; } if(fifo.head==NULL && a==2) { printf("\nKolejka pusta"); } free(fifo.head); } if(a==3) return 0; } }